internal override void OnEditBegun(DataGridItemEventArgs e)
        {
            object item = e.Item;

            DataGridPageManagerBase pageManager = this.RootGroup.GetVirtualPageManager();

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

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

                for (int i = 0; i < count; i++)
                {
                    DataGridItemPropertyBase itemProperty = itemProperties[i];
                    propertyNames[i] = itemProperty.Name;
                    cachedValues[i]  = itemProperty.GetValue(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);
        }
コード例 #2
0
            public override object GetValue(object component)
            {
                DataGridItemPropertyBase dataGridItemProperty = this.DataGridItemProperty;

                if (dataGridItemProperty == null)
                {
                    return(null);
                }

                return(dataGridItemProperty.GetValue(base.GetValue(component)));
            }
コード例 #3
0
        public int Compare(RawItem xRawItem, RawItem yRawItem)
        {
            if (xRawItem == null)
            {
                if (yRawItem == null)
                {
                    return(0);
                }
                else
                {
                    return(-1);
                }
            }
            else
            {
                if (yRawItem == null)
                {
                    return(1);
                }
            }

            ListSortDirection         lastSortDirection = ListSortDirection.Ascending;
            SortDescriptionCollection sortDescriptions  = m_collectionView.SortDescriptions;
            int sortDescriptionCount = sortDescriptions.Count;

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

                for (int i = 0; i < sortDescriptionCount; i++)
                {
                    SortDescription sortDescription = sortDescriptions[i];
                    lastSortDirection = sortDescription.Direction;
                    DataGridItemPropertyBase dataProperty = itemProperties[sortDescription.PropertyName];

                    if (dataProperty == null)
                    {
                        continue;
                    }

                    ISupportInitialize supportInitialize = dataProperty as ISupportInitialize;
                    object             xData             = null;
                    object             yData             = null;

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

                    try
                    {
                        xData = dataProperty.GetValue(xRawItem.DataItem);
                        yData = dataProperty.GetValue(yRawItem.DataItem);
                    }
                    finally
                    {
                        if (supportInitialize != null)
                        {
                            supportInitialize.EndInit();
                        }
                    }

                    IComparer sortComparer = dataProperty.SortComparer;

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

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

                        return(result);
                    }
                }
            }

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

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