本文整理汇总了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);
}
}