本文整理汇总了C#中DataGridContext.GetBindingPathExtractorForColumn方法的典型用法代码示例。如果您正苦于以下问题:C# DataGridContext.GetBindingPathExtractorForColumn方法的具体用法?C# DataGridContext.GetBindingPathExtractorForColumn怎么用?C# DataGridContext.GetBindingPathExtractorForColumn使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类DataGridContext
的用法示例。
在下文中一共展示了DataGridContext.GetBindingPathExtractorForColumn方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ExportDataItemCore
private void ExportDataItemCore( DataGridContext dataGridContext, ClipboardExporterBase clipboardExporter, int itemIndex, object item, int[] exportedVisiblePositions,
ColumnBase[] columnsByVisiblePosition )
{
DataGridCollectionViewBase dataGridCollectionViewBase = dataGridContext.ItemsSourceCollection as DataGridCollectionViewBase;
clipboardExporter.StartDataItem( dataGridContext, item );
// Ensure the count does not exceeds the columns count
int exportedVisiblePositionsCount = exportedVisiblePositions.Length;
exportedVisiblePositionsCount = Math.Min( exportedVisiblePositionsCount, columnsByVisiblePosition.Length );
HashSet<int> intersectedIndexes = this.GetIntersectedRangesForIndex( dataGridContext, itemIndex, exportedVisiblePositions, exportedVisiblePositionsCount );
object fieldValue = null;
Column column = null;
for( int i = 0; i < exportedVisiblePositionsCount; i++ )
{
// Reset field value
fieldValue = null;
int visiblePosition = exportedVisiblePositions[ i ];
// Export null if not intersected by a SelectionRange
if( intersectedIndexes.Contains( visiblePosition ) )
{
// Only export visible data column
column = columnsByVisiblePosition[ visiblePosition ] as Column;
if( column == null )
continue;
// Use DataGridCollectionView directly since the DataGridItemProperty uses PropertyDescriptor which increase
// the read of the field value
DataGridItemPropertyBase dataGridItemProperty = null;
// Try to get a DataGridItemProperty matching the column FieldName
// and get the value from it
if( dataGridCollectionViewBase != null )
{
dataGridItemProperty = dataGridCollectionViewBase.ItemProperties[ column.FieldName ];
if( dataGridItemProperty != null )
{
fieldValue = dataGridItemProperty.GetValue( item );
}
}
// If none was found, create a BindingPathValueExtractor from this column
if( ( dataGridCollectionViewBase == null ) || ( dataGridItemProperty == null ) )
{
// We don't have a DataGridCollectionView, use a BindingPathValueExtractor
// to create a binding to help us get the value for the Column in the
// data item
BindingPathValueExtractor extractorForRead = null;
if( m_columnToBindingPathExtractor.TryGetValue( column, out extractorForRead ) == false )
{
extractorForRead = dataGridContext.GetBindingPathExtractorForColumn( column, item );
m_columnToBindingPathExtractor.Add( column, extractorForRead );
}
fieldValue = extractorForRead.GetValueFromItem( item );
}
}
if( fieldValue != null )
{
//Verify if the value should be converted to the displayed value for exporting.
ForeignKeyConfiguration foreignKeyConfiguration = column.ForeignKeyConfiguration;
if( foreignKeyConfiguration != null && foreignKeyConfiguration.UseDisplayedValueWhenExporting )
{
fieldValue = foreignKeyConfiguration.GetDisplayMemberValue( fieldValue );
}
else if( column.DisplayedValueConverter != null )
{
fieldValue = column.DisplayedValueConverter.Convert( fieldValue, typeof( object ), column.DisplayedValueConverterParameter, column.GetCulture( column.DisplayedValueConverterCulture ) );
}
else if( !string.IsNullOrEmpty( column.CellContentStringFormat ) )
{
fieldValue = string.Format( column.GetCulture(), column.CellContentStringFormat, fieldValue );
}
}
clipboardExporter.StartDataItemField( dataGridContext, column, fieldValue );
clipboardExporter.EndDataItemField( dataGridContext, column, fieldValue );
}
clipboardExporter.EndDataItem( dataGridContext, item );
}
示例2: ExportDataItemCore
private void ExportDataItemCore(
DataGridContext dataGridContext,
ClipboardExporterBase clipboardExporter,
int itemIndex,
object item,
int[] exportedVisiblePositions,
ColumnBase[] columnsByVisiblePosition )
{
DataGridCollectionViewBase dataGridCollectionViewBase =
dataGridContext.ItemsSourceCollection as DataGridCollectionViewBase;
clipboardExporter.StartDataItem( dataGridContext, item );
// Ensure the count does not exceeds the columns count
int exportedVisiblePositionsCount = exportedVisiblePositions.Length;
exportedVisiblePositionsCount = Math.Min( exportedVisiblePositionsCount, columnsByVisiblePosition.Length );
HashSet<int> intersectedIndexes = this.GetIntersectedRangesForIndex( dataGridContext,
itemIndex,
exportedVisiblePositions,
exportedVisiblePositionsCount );
object fieldValue = null;
Column column = null;
for( int i = 0; i < exportedVisiblePositionsCount; i++ )
{
int visiblePosition = exportedVisiblePositions[ i ];
// Export null if not intersected by a SelectionRange
if( intersectedIndexes.Contains( visiblePosition ) )
{
// Only export visible data column
column = columnsByVisiblePosition[ visiblePosition ] as Column;
if( column == null )
continue;
// Reset field value
fieldValue = null;
// Use DataGridCollectionView directly since the DataGridItemProperty uses PropertyDescriptor which increase
// the read of the field value
DataGridItemPropertyBase dataGridItemProperty = null;
// Try to get a DataGridItemProperty matching the column FieldName
// and get the value from it
if( dataGridCollectionViewBase != null )
{
dataGridItemProperty = dataGridCollectionViewBase.ItemProperties[ column.FieldName ];
if( dataGridItemProperty != null )
fieldValue = dataGridItemProperty.GetValue( item );
}
// If none was found, create a BindingPathValueExtractor from this column
if( ( dataGridCollectionViewBase == null ) || ( dataGridItemProperty == null ) )
{
// We don't have a DataGridCollectionView, use a BindingPathValueExtractor
// to create a binding to help us get the value for the Column in the
// data item
BindingPathValueExtractor extractorForRead = null;
if( m_columnToBindingPathExtractor.TryGetValue( column, out extractorForRead ) == false )
{
extractorForRead = dataGridContext.GetBindingPathExtractorForColumn( column, item );
m_columnToBindingPathExtractor.Add( column, extractorForRead );
}
fieldValue = extractorForRead.GetValueFromItem( item );
}
}
clipboardExporter.StartDataItemField( dataGridContext, column, fieldValue );
clipboardExporter.EndDataItemField( dataGridContext, column, fieldValue );
}
clipboardExporter.EndDataItem( dataGridContext, item );
}