internal override void OnEditBegun(DataGridItemEventArgs e)
        {
            var item        = e.Item;
            var pageManager = this.RootGroup.GetVirtualPageManager();

            if (!pageManager.IsItemDirty(item))
            {
                // First time we enter edit on this item.
                var itemProperties = this.ItemProperties;
                var count          = itemProperties.Count;

                var propertyNames = new string[count];
                var cachedValues  = new object[count];

                for (int i = 0; i < count; i++)
                {
                    var itemProperty = itemProperties[i];

                    propertyNames[i] = PropertyRouteParser.Parse(itemProperty);
                    cachedValues[i]  = ItemsSourceHelper.GetValueFromItemProperty(itemProperty, item);
                }

                // Cache the values of the never edited before row.  This will help the developer find the corresponding row
                // in the source when times comes to commit the changes to the data source.
                pageManager.SetCachedValuesForItem(item, propertyNames, cachedValues);
            }

            base.OnEditBegun(e);
        }
        internal override void OnEditCanceled(DataGridItemEventArgs e)
        {
            var item        = e.Item;
            var pageManager = this.RootGroup.GetVirtualPageManager();

            // Compare cached values with current values.  If they are the same, we can clear the old values which in turn will
            // make the item non dirty.
            var clearIsDirty = true;

            var cachedValues = pageManager.GetCachedValuesForItem(item);

            Debug.Assert(cachedValues != null);

            var itemProperties = this.ItemProperties;

            foreach (var itemProperty in itemProperties)
            {
                var currentValue = ItemsSourceHelper.GetValueFromItemProperty(itemProperty, item);

                if (!(object.Equals(currentValue, cachedValues[PropertyRouteParser.Parse(itemProperty)])))
                {
                    clearIsDirty = false;
                    break;
                }
            }

            if (clearIsDirty)
            {
                pageManager.ClearCachedValuesForItem(item);
            }

            base.OnEditCanceled(e);
        }
        protected object GetPropertyValue(object item)
        {
            if (m_contextProperty != null)
            {
                return(ItemsSourceHelper.GetValueFromItemProperty(m_contextProperty, item));
            }

            return(m_propertyGroupDescription.GroupNameFromItem(item, 0, CultureInfo.InvariantCulture));
        }
            private void ExportDataItemCore(DataGridContext dataGridContext, ClipboardExporterBase clipboardExporter, int itemIndex, object item,
                                            int[] exportedVisiblePositions, ColumnBase[] columnsByVisiblePosition)
            {
                var dataGridCollectionViewBase = dataGridContext.ItemsSourceCollection as DataGridCollectionViewBase;

                clipboardExporter.StartDataItem(dataGridContext, item);

                // Ensure the count does not exceeds the columns count
                var exportedVisiblePositionsCount = exportedVisiblePositions.Length;

                exportedVisiblePositionsCount = Math.Min(exportedVisiblePositionsCount, columnsByVisiblePosition.Length);

                var intersectedIndexes = this.GetIntersectedRangesForIndex(dataGridContext, itemIndex, exportedVisiblePositions, exportedVisiblePositionsCount);

                for (int i = 0; i < exportedVisiblePositionsCount; i++)
                {
                    var fieldValue      = default(object);
                    var column          = default(Column);
                    var 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
                        var dataGridItemProperty = default(DataGridItemPropertyBase);

                        // Try to get a DataGridItemProperty matching the column FieldName and get the value from it
                        if (dataGridCollectionViewBase != null)
                        {
                            dataGridItemProperty = ItemsSourceHelper.GetItemPropertyFromProperty(dataGridCollectionViewBase.ItemProperties, column.FieldName);

                            if (dataGridItemProperty != null)
                            {
                                fieldValue = ItemsSourceHelper.GetValueFromItemProperty(dataGridItemProperty, 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
                            var extractorForRead = default(BindingPathValueExtractor);

                            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.
                        var foreignKeyConfiguration = column.ForeignKeyConfiguration;
                        if (foreignKeyConfiguration != null && foreignKeyConfiguration.UseDisplayedValueWhenExporting)
                        {
                            fieldValue = foreignKeyConfiguration.GetDisplayMemberValue(fieldValue);
                        }
                        else
                        {
                            var valueConverter = column.DisplayedValueConverter;
                            if (valueConverter != null)
                            {
                                fieldValue = valueConverter.Convert(fieldValue, typeof(object), column.DisplayedValueConverterParameter,
                                                                    column.GetCulture(column.DisplayedValueConverterCulture));
                            }
                            else
                            {
                                var valueFormat = column.CellContentStringFormat;
                                if (!string.IsNullOrEmpty(valueFormat))
                                {
                                    fieldValue = string.Format(column.GetCulture(), valueFormat, fieldValue);
                                }
                            }
                        }
                    }

                    clipboardExporter.StartDataItemField(dataGridContext, column, fieldValue);
                    clipboardExporter.EndDataItemField(dataGridContext, column, fieldValue);
                }

                clipboardExporter.EndDataItem(dataGridContext, item);
            }
        public int Compare(RawItem xRawItem, RawItem yRawItem)
        {
            if (xRawItem == null)
            {
                return((yRawItem == null) ? 0 : -1);
            }

            if (yRawItem == null)
            {
                return(1);
            }

            var lastSortDirection    = ListSortDirection.Ascending;
            var sortDescriptions     = m_collectionView.SortDescriptions;
            var sortDescriptionCount = sortDescriptions.Count;

            if (sortDescriptionCount > 0)
            {
                var result         = default(int);
                var itemProperties = m_collectionView.ItemProperties;

                for (int i = 0; i < sortDescriptionCount; i++)
                {
                    var sortDescription = sortDescriptions[i];
                    lastSortDirection = sortDescription.Direction;

                    var itemProperty = ItemsSourceHelper.GetItemPropertyFromProperty(itemProperties, sortDescription.PropertyName);
                    if (itemProperty == null)
                    {
                        continue;
                    }

                    var supportInitialize = itemProperty as ISupportInitialize;
                    var xData             = default(object);
                    var yData             = default(object);

                    if (supportInitialize != null)
                    {
                        supportInitialize.BeginInit();
                    }

                    try
                    {
                        xData = ItemsSourceHelper.GetValueFromItemProperty(itemProperty, xRawItem.DataItem);
                        yData = ItemsSourceHelper.GetValueFromItemProperty(itemProperty, yRawItem.DataItem);

                        if (itemProperty.IsSortingOnForeignKeyDescription)
                        {
                            var foreignKeyDescription = itemProperty.ForeignKeyDescription;

                            xData = foreignKeyDescription.GetDisplayValue(xData);
                            yData = foreignKeyDescription.GetDisplayValue(yData);
                        }
                    }
                    finally
                    {
                        if (supportInitialize != null)
                        {
                            supportInitialize.EndInit();
                        }
                    }

                    var sortComparer = itemProperty.SortComparer;

                    if (sortComparer != null)
                    {
                        result = sortComparer.Compare(xData, yData);
                    }
                    else
                    {
                        result = ObjectDataStore.CompareData(xData, yData);
                    }

                    if (result != 0)
                    {
                        if (lastSortDirection == ListSortDirection.Descending)
                        {
                            return(-result);
                        }

                        return(result);
                    }
                }
            }

            if (lastSortDirection == ListSortDirection.Descending)
            {
                return(yRawItem.Index - xRawItem.Index);
            }

            return(xRawItem.Index - yRawItem.Index);
        }