protected override string GetNameCore()
        {
            AutomationPeer wrapperPeer = this.GetWrapperPeer();
            string         name        = null;

            if (wrapperPeer != null)
            {
                name = wrapperPeer.GetName();
            }

            if ((name == null) && (m_item is string))
            {
                name = ( string )m_item;
            }

            if (!string.IsNullOrEmpty(name))
            {
                return(name);
            }

            Column mainColumn = this.DataGridContext.Columns.MainColumn as Column;

            if ((mainColumn == null) || (!mainColumn.Visible))
            {
                return(string.Empty);
            }

            BindingPathValueExtractor valueExtractor = this.DataGridContext.GetBindingPathExtractorForColumn(mainColumn, m_item);
            object mainColumnValue = valueExtractor.GetValueFromItem(m_item);

            if (mainColumnValue == null)
            {
                return(string.Empty);
            }

            return(string.Format(CultureInfo.CurrentCulture, "{0}", mainColumnValue));
        }
Esempio n. 2
0
            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 eNequeos the columns count
                int exportedVisiblePositionsCount = exportedVisiblePositions.Length;

                exportedVisiblePositionsCount = System.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);
            }
            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);
            }