当前位置: 首页>>代码示例>>C#>>正文


C# DataGrid.Empty方法代码示例

本文整理汇总了C#中DataGrid.Empty方法的典型用法代码示例。如果您正苦于以下问题:C# DataGrid.Empty方法的具体用法?C# DataGrid.Empty怎么用?C# DataGrid.Empty使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在DataGrid的用法示例。


在下文中一共展示了DataGrid.Empty方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Populate

        public virtual void Populate(DataGrid dataGrid)
        {
            if (dataGrid == null) throw new ArgumentNullException("dataGrid");

            try
            {
                Log.Info("Beginning Data Import...");
                DataGrid rawData = ReadRawData(dataGrid.Columns);
                if (!rawData.Rows.Any())
                {
                    throw new AbortException("Specified Data Source is empty.");
                }
                Log.Info(String.Format("Data successfully read from file. Total Rows: {0}.", rawData.Rows.Count()));

                /*
                *  Headers
                */

                Log.Info("Processing headers from imported data...");
                ProcessHeaders(dataGrid.Columns, rawData);
                Log.Info("Headers successfully processed.");

                /*
                *  Data
                */

                dataGrid.Empty();
                Log.Info("Processing imported data...");
                foreach (DataGridRow rawDataRow in rawData.Rows)
                {
                    Log.Trace(String.Format("Processing imported row '{0}'.", rawDataRow.Index()));

                    // Pass 1: Process Raw Data from Source
                    DataGridRow dataGridRow = dataGrid.Rows.New();
                    foreach (DataGridColumn dataColumn in dataGrid.Columns)
                    {
                        try
                        {
                            object cellValue = GetValue(dataColumn, rawDataRow);
                            DataGridCell cell = (cellValue != null) ? dataColumn.Cell(cellValue) : dataColumn.Cell();
                            dataGridRow.Cells.Add(cell);
                        }
                        catch (Exception exception)
                        {
                            throw new AbortException(String.Format("An error occurred while reading cell at Row: '{0}', Column: '{1}'."
                                , dataGridRow.Index() + 1
                                , dataColumn)
                                , exception);
                        }
                    }

                    // Pass 2: Process Mapped Columns
                    foreach (DataGridColumn mappedColumn in dataGrid.Columns.Where(match => match.HasMappedColumns))
                    {
                        try
                        {
                            DataGridCell cell = dataGridRow[mappedColumn.ColumnName];
                            object cellValue = GetMappedValue(mappedColumn, dataGridRow);
                            cell.OriginalValue = cellValue;
                        }
                        catch (Exception exception)
                        {
                            throw new AbortException(String.Format("An error occurred while reading cell at Row: '{0}', Column: '{1}'."
                                , dataGridRow.Index() + 1
                                , mappedColumn)
                                , exception);
                        }
                    }
                }

                Log.Info(String.Format("Imported data successfully processed. Total Rows processed: {0}", dataGrid.Rows.Count()));
            }
            catch (AbortException exception)
            {
                Log.Critrical("Data Import Failed!", exception);
                throw exception;
            }
            catch (Exception exception)
            {
                Log.Error("An unexpected Error occurred…", exception);
                Log.Critrical("Data Import Failed!");
                throw new AbortException(exception.Message, exception);
            }
        }
开发者ID:onesimoh,项目名称:Andamio,代码行数:84,代码来源:ImportReader.cs


注:本文中的DataGrid.Empty方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。