コード例 #1
0
        private void RemoveAt(int index, bool selectCurrentRow)
        {
            if (index < 0 || index >= this.Count)
            {
                throw new IndexOutOfRangeException("Invalid Index.");
            }
            GridViewRowInfo gridViewRowInfo = this[index];
            GridViewInfo    viewInfo        = gridViewRowInfo.ViewInfo;

            if (this.OnRowsChanging(new GridViewCollectionChangingEventArgs(this.owner, NotifyCollectionChangedAction.Remove, (object)gridViewRowInfo, -1, index)))
            {
                return;
            }
            int count = this.Count;

            GridViewSynchronizationService.SuspendEvent(this.owner, KnownEvents.CurrentChanged);
            GridViewRowInfo navRow = (GridViewRowInfo)null;
            bool            flag   = selectCurrentRow && this.owner.MasterTemplate != null && gridViewRowInfo == this.owner.MasterTemplate.CurrentRow;

            if (flag)
            {
                navRow = GridViewRowCollection.NavigateAfterRemove(this.owner.MasterTemplate.CurrentRow, (List <GridViewRowInfo>)null);
            }
            this.suspendNotifications = true;
            gridViewRowInfo.ViewInfo.PinnedRows.Remove(gridViewRowInfo);
            this.owner.ListSource.RemoveAt(index);
            this.suspendNotifications = false;
            GridViewSynchronizationService.ResumeEvent(this.owner, KnownEvents.CurrentChanged);
            if (count != this.Count)
            {
                this.DispatchDataViewChangedEvent(new DataViewChangedEventArgs(ViewChangedAction.Remove, (object)gridViewRowInfo));
                if (flag)
                {
                    if (navRow == null && this.Owner.AllowAddNewRow)
                    {
                        navRow = (GridViewRowInfo)viewInfo.TableAddNewRow;
                    }
                    if (navRow != null && navRow.ViewInfo != null)
                    {
                        this.ExpandRow(navRow);
                        this.owner.MasterTemplate.CurrentRow = navRow;
                    }
                    if (this.Owner.MasterTemplate.CurrentRow == null)
                    {
                        this.Owner.MasterTemplate.EventDispatcher.RaiseEvent <EventArgs>(EventDispatcher.SelectionChanged, (object)this.Owner, EventArgs.Empty);
                    }
                }
                gridViewRowInfo.Detach();
            }
            else
            {
                gridViewRowInfo.Attach();
                if (!gridViewRowInfo.IsPinned)
                {
                    return;
                }
                viewInfo.PinnedRows.Add(gridViewRowInfo);
            }
        }
コード例 #2
0
        internal static GridViewRowInfo NavigateAfterRemove(
            GridViewRowInfo startFrom,
            List <GridViewRowInfo> notAllowedRows)
        {
            GridViewRowInfo row           = startFrom;
            GridTraverser   gridTraverser = new GridTraverser(row.ViewInfo);

            gridTraverser.GoToRow(row);
            GridTraverser.GridTraverserPosition position = gridTraverser.Position;
            GridViewRowInfo newCurrentRowInfo            = GridViewRowCollection.ChangeTheChildViewAfterRemove(startFrom);

            if (newCurrentRowInfo != null)
            {
                return(newCurrentRowInfo);
            }
            while (gridTraverser.MoveNext())
            {
                if (gridTraverser.Current.CanBeCurrent && (notAllowedRows == null || !notAllowedRows.Contains(gridTraverser.Current)))
                {
                    if (gridTraverser.Current is GridViewGroupRowInfo)
                    {
                        if (!gridTraverser.Current.IsExpanded)
                        {
                            gridTraverser.Current.IsExpanded = true;
                        }
                    }
                    else
                    {
                        if (gridTraverser.Current is GridViewDataRowInfo || gridTraverser.Current is GridViewNewRowInfo)
                        {
                            newCurrentRowInfo = gridTraverser.Current;
                            break;
                        }
                        break;
                    }
                }
            }
            if (newCurrentRowInfo == null)
            {
                gridTraverser.Position         = position;
                gridTraverser.ProcessHierarchy = true;
                while (gridTraverser.MovePrevious())
                {
                    if (gridTraverser.Current.CanBeCurrent && (notAllowedRows == null || !notAllowedRows.Contains(gridTraverser.Current)))
                    {
                        if (gridTraverser.Current is GridViewGroupRowInfo)
                        {
                            if (!gridTraverser.Current.IsExpanded)
                            {
                                gridTraverser.Current.IsExpanded = true;
                                gridTraverser.Position           = position;
                            }
                        }
                        else
                        {
                            if (gridTraverser.Current is GridViewDataRowInfo || gridTraverser.Current is GridViewNewRowInfo)
                            {
                                newCurrentRowInfo = gridTraverser.Current;
                                break;
                            }
                            position = gridTraverser.Position;
                        }
                    }
                }
            }
            if (newCurrentRowInfo == null)
            {
                return((GridViewRowInfo)null);
            }
            if (GridViewRowCollection.HasDeletedParentRow(newCurrentRowInfo, notAllowedRows))
            {
                newCurrentRowInfo = GridViewRowCollection.NavigateAfterRemove(newCurrentRowInfo.Parent as GridViewRowInfo, notAllowedRows);
            }
            return(newCurrentRowInfo);
        }
コード例 #3
0
        private void ListSource_CollectionChanged(object sender, NotifyCollectionChangedEventArgs e)
        {
            if (e.Action == NotifyCollectionChangedAction.Add)
            {
                this.AttachRows(e.NewItems);
                if (!this.suspendNotifications)
                {
                    if (this.Count <= 1)
                    {
                        this.owner.DataView.EnsureDescriptors();
                    }
                    this.UpdateChildRowViewInfo((GridViewRowInfo)e.NewItems[0]);
                    if (((GridViewRowInfo)e.NewItems[0]).Parent is MasterGridViewTemplate)
                    {
                        ++((GridViewRowInfo)e.NewItems[0]).ViewInfo.Version;
                    }
                    this.DispatchDataViewChangedEvent(new DataViewChangedEventArgs(ViewChangedAction.Add, e.NewItems));
                    if (this.owner.SelectLastAddedRow && e.NewItems.Count > 0)
                    {
                        GridViewSynchronizationService.RaiseCurrentChanged(this.owner, this.owner.DataView.CurrentItem, this.owner.CurrentColumn, this.owner.DataView == null);
                        if (!this.addingThroughUI)
                        {
                            if (this.prevSelectedRow != null)
                            {
                                GridViewSynchronizationService.SuspendEvent(this.owner, KnownEvents.CurrentChanged);
                                this.prevSelectedRow.IsCurrent  = false;
                                this.prevSelectedRow.IsSelected = false;
                                GridViewSynchronizationService.ResumeEvent(this.owner, KnownEvents.CurrentChanged);
                            }
                            GridViewRowInfo newItem = (GridViewRowInfo)e.NewItems[0];
                            newItem.IsCurrent    = true;
                            newItem.IsSelected   = true;
                            this.prevSelectedRow = newItem;
                            newItem.EnsureVisible();
                        }
                    }
                    if (this.owner.IsSelfReference)
                    {
                        this.DispatchDataViewChangedEvent(new DataViewChangedEventArgs(ViewChangedAction.SortingChanged));
                    }
                }
            }
            GridViewInfo    gridViewInfo    = (GridViewInfo)null;
            GridViewRowInfo gridViewRowInfo = (GridViewRowInfo)null;
            bool            flag1           = false;

            if (e.Action == NotifyCollectionChangedAction.Remove)
            {
                GridViewRowInfo newItem = e.NewItems[0] as GridViewRowInfo;
                flag1 = newItem.IsPinned;
                if (newItem != null && newItem.ViewTemplate != null && newItem.ViewTemplate.HierarchyDataProvider != null)
                {
                    int val1 = this.owner.MasterTemplate.Owner.TableElement.RowScroller.Scrollbar.Value;
                    newItem.ViewTemplate.HierarchyDataProvider.Refresh();
                    newItem.ViewTemplate.Refresh();
                    RadScrollBarElement scrollbar = this.owner.MasterTemplate.Owner.TableElement.RowScroller.Scrollbar;
                    scrollbar.Value = Math.Min(val1, scrollbar.Maximum - scrollbar.LargeChange + 1);
                }
                if (newItem != null && newItem.IsCurrent && (this.owner.Parent != null && !this.suspendNotifications))
                {
                    gridViewInfo    = newItem.ViewInfo;
                    gridViewRowInfo = GridViewRowCollection.NavigateAfterRemove(newItem, (List <GridViewRowInfo>)null);
                }
                if (!this.suspendNotifications)
                {
                    this.DispatchDataViewChangedEvent(new DataViewChangedEventArgs(ViewChangedAction.Remove, e.NewItems));
                }
            }
            this.OnCollectionChanged(e);
            if (gridViewInfo != null)
            {
                GridViewRelationDataProvider hierarchyDataProvider = gridViewInfo.ViewTemplate.HierarchyDataProvider as GridViewRelationDataProvider;
                if (hierarchyDataProvider != null && this.owner.MasterTemplate.SynchronizationService.IsDispatchSuspended)
                {
                    hierarchyDataProvider.Refresh();
                }
                gridViewInfo.Refresh();
            }
            GridViewCollectionChangedEventArgs args = new GridViewCollectionChangedEventArgs(this.owner, e.Action, e.NewItems, e.OldItems, e.NewStartingIndex, e.OldStartingIndex, e.PropertyName);
            bool flag2 = true;

            if (e.Action == NotifyCollectionChangedAction.ItemChanging || e.Action == NotifyCollectionChangedAction.ItemChanged)
            {
                flag2 = !this.owner.ListSource.IsDataBound || e.Action == NotifyCollectionChangedAction.ItemChanged && !string.IsNullOrEmpty(e.PropertyName);
            }
            if (flag2)
            {
                this.owner.EventDispatcher.RaiseEvent <GridViewCollectionChangedEventArgs>(EventDispatcher.RowsChanged, (object)this, args);
                this.UpdateHierarchyView(e.NewItems, e.PropertyName);
            }
            if (flag1)
            {
                this.DispatchDataViewChangedEvent(new DataViewChangedEventArgs(ViewChangedAction.Remove), GridEventType.UI);
            }
            if (gridViewInfo == null || this.owner.MasterTemplate == null)
            {
                return;
            }
            if (this.owner.MasterTemplate.SynchronizationService.IsDispatchSuspended)
            {
                if (gridViewRowInfo == null)
                {
                    return;
                }
                this.owner.MasterTemplate.CurrentRowToSetOnEndUpdate = gridViewRowInfo;
            }
            else
            {
                if (!flag1)
                {
                    this.DispatchDataViewChangedEvent(new DataViewChangedEventArgs(ViewChangedAction.Remove), GridEventType.UI);
                }
                if (gridViewRowInfo == null)
                {
                    return;
                }
                this.owner.MasterTemplate.CurrentRow = gridViewRowInfo;
            }
        }