private void UpdateRowCaches(int rowIndex, ref DataGridViewRow dataGridViewRow, bool adding)
 {
     if (((this.rowCountsVisible != -1) || (this.rowCountsVisibleFrozen != -1)) || (((this.rowCountsVisibleSelected != -1) || (this.rowsHeightVisible != -1)) || (this.rowsHeightVisibleFrozen != -1)))
     {
         DataGridViewElementStates rowState = this.GetRowState(rowIndex);
         if ((rowState & DataGridViewElementStates.Visible) != DataGridViewElementStates.None)
         {
             int num = adding ? 1 : -1;
             int num2 = 0;
             if ((this.rowsHeightVisible != -1) || ((this.rowsHeightVisibleFrozen != -1) && ((rowState & (DataGridViewElementStates.Visible | DataGridViewElementStates.Frozen)) == (DataGridViewElementStates.Visible | DataGridViewElementStates.Frozen))))
             {
                 num2 = adding ? dataGridViewRow.GetHeight(rowIndex) : -dataGridViewRow.GetHeight(rowIndex);
                 dataGridViewRow = this.SharedRow(rowIndex);
             }
             if (this.rowCountsVisible != -1)
             {
                 this.rowCountsVisible += num;
             }
             if (this.rowsHeightVisible != -1)
             {
                 this.rowsHeightVisible += num2;
             }
             if ((rowState & (DataGridViewElementStates.Visible | DataGridViewElementStates.Frozen)) == (DataGridViewElementStates.Visible | DataGridViewElementStates.Frozen))
             {
                 if (this.rowCountsVisibleFrozen != -1)
                 {
                     this.rowCountsVisibleFrozen += num;
                 }
                 if (this.rowsHeightVisibleFrozen != -1)
                 {
                     this.rowsHeightVisibleFrozen += num2;
                 }
             }
             if (((rowState & (DataGridViewElementStates.Visible | DataGridViewElementStates.Selected)) == (DataGridViewElementStates.Visible | DataGridViewElementStates.Selected)) && (this.rowCountsVisibleSelected != -1))
             {
                 this.rowCountsVisibleSelected += num;
             }
         }
     }
 }
コード例 #2
0
        private void UpdateRowCaches(int rowIndex, ref DataGridViewRow dataGridViewRow, bool adding)
        {
            if (this.rowCountsVisible != -1 || this.rowCountsVisibleFrozen != -1 || this.rowCountsVisibleSelected != -1 ||
                this.rowsHeightVisible != -1 || this.rowsHeightVisibleFrozen != -1)
            {
                DataGridViewElementStates rowStates = GetRowState(rowIndex);
                if ((rowStates & DataGridViewElementStates.Visible) != 0)
                {
                    int rowCountIncrement = adding ? 1 : -1;
                    int rowHeightIncrement = 0;
                    if (this.rowsHeightVisible != -1 || 
                        (this.rowsHeightVisibleFrozen != -1 && 
                         ((rowStates & (DataGridViewElementStates.Visible | DataGridViewElementStates.Frozen)) == (DataGridViewElementStates.Visible | DataGridViewElementStates.Frozen))))
                    {
                        // dataGridViewRow may become unshared in GetHeight call
                        rowHeightIncrement = adding ? dataGridViewRow.GetHeight(rowIndex) : -dataGridViewRow.GetHeight(rowIndex);
                        dataGridViewRow = SharedRow(rowIndex);
                    }
                    
                    if (this.rowCountsVisible != -1)
                    {
                        this.rowCountsVisible += rowCountIncrement;
                    }
                    if (this.rowsHeightVisible != -1)
                    {
                        Debug.Assert(rowHeightIncrement != 0);
                        this.rowsHeightVisible += rowHeightIncrement;
                    }
                    
                    if ((rowStates & (DataGridViewElementStates.Visible | DataGridViewElementStates.Frozen)) == (DataGridViewElementStates.Visible | DataGridViewElementStates.Frozen))
                    {
                        if (this.rowCountsVisibleFrozen != -1)
                        {
                            this.rowCountsVisibleFrozen += rowCountIncrement;
                        }
                        if (this.rowsHeightVisibleFrozen != -1)
                        {
                            Debug.Assert(rowHeightIncrement != 0);
                            this.rowsHeightVisibleFrozen += rowHeightIncrement;
                        }
                    }

                    if ((rowStates & (DataGridViewElementStates.Visible | DataGridViewElementStates.Selected)) == (DataGridViewElementStates.Visible | DataGridViewElementStates.Selected))
                    {
                        if (this.rowCountsVisibleSelected != -1)
                        {
                            this.rowCountsVisibleSelected += rowCountIncrement;
                        }
                    }
                }
            }

#if DEBUG
            this.cachedRowCountsAccessAllowed = true;
            this.cachedRowHeightsAccessAllowed = true;
#endif
        }
        private void OnCollectionChanged_PreNotification(CollectionChangeAction cca, int rowIndex, int rowCount, ref DataGridViewRow dataGridViewRow, bool changeIsInsertion)
        {
            int height;
            bool useRowShortcut = false;
            bool computeVisibleRows = false;
            switch (cca)
            {
                case CollectionChangeAction.Add:
                    height = 0;
                    this.UpdateRowCaches(rowIndex, ref dataGridViewRow, true);
                    if ((this.GetRowState(rowIndex) & DataGridViewElementStates.Visible) != DataGridViewElementStates.None)
                    {
                        int firstDisplayedRowIndex = this.DataGridView.FirstDisplayedRowIndex;
                        if (firstDisplayedRowIndex != -1)
                        {
                            height = this.SharedRow(firstDisplayedRowIndex).GetHeight(firstDisplayedRowIndex);
                        }
                        break;
                    }
                    useRowShortcut = true;
                    computeVisibleRows = changeIsInsertion;
                    break;

                case CollectionChangeAction.Remove:
                {
                    DataGridViewElementStates rowState = this.GetRowState(rowIndex);
                    bool flag3 = (rowState & DataGridViewElementStates.Visible) != DataGridViewElementStates.None;
                    bool flag4 = (rowState & DataGridViewElementStates.Frozen) != DataGridViewElementStates.None;
                    this.rowStates.RemoveAt(rowIndex);
                    this.SharedList.RemoveAt(rowIndex);
                    this.DataGridView.OnRemovedRow_PreNotification(rowIndex);
                    if (!flag3)
                    {
                        useRowShortcut = true;
                    }
                    else if (!flag4)
                    {
                        if ((this.DataGridView.FirstDisplayedScrollingRowIndex != -1) && (rowIndex > this.DataGridView.FirstDisplayedScrollingRowIndex))
                        {
                            int num4 = 0;
                            int num5 = this.DataGridView.FirstDisplayedRowIndex;
                            if (num5 != -1)
                            {
                                num4 = this.SharedRow(num5).GetHeight(num5);
                            }
                            useRowShortcut = this.GetRowsHeightExceedLimit(DataGridViewElementStates.Visible, 0, rowIndex, (this.DataGridView.LayoutInfo.Data.Height + this.DataGridView.VerticalScrollingOffset) + SystemInformation.HorizontalScrollBarHeight) && (num4 <= this.DataGridView.LayoutInfo.Data.Height);
                        }
                    }
                    else
                    {
                        useRowShortcut = (this.DataGridView.FirstDisplayedScrollingRowIndex == -1) && this.GetRowsHeightExceedLimit(DataGridViewElementStates.Visible, 0, rowIndex, this.DataGridView.LayoutInfo.Data.Height + SystemInformation.HorizontalScrollBarHeight);
                    }
                    goto Label_02DF;
                }
                case CollectionChangeAction.Refresh:
                    this.InvalidateCachedRowCounts();
                    this.InvalidateCachedRowsHeights();
                    goto Label_02DF;

                default:
                    goto Label_02DF;
            }
            if (changeIsInsertion)
            {
                this.DataGridView.OnInsertedRow_PreNotification(rowIndex, 1);
                if (!useRowShortcut)
                {
                    if ((this.GetRowState(rowIndex) & DataGridViewElementStates.Frozen) != DataGridViewElementStates.None)
                    {
                        useRowShortcut = (this.DataGridView.FirstDisplayedScrollingRowIndex == -1) && this.GetRowsHeightExceedLimit(DataGridViewElementStates.Visible, 0, rowIndex, this.DataGridView.LayoutInfo.Data.Height);
                    }
                    else if ((this.DataGridView.FirstDisplayedScrollingRowIndex != -1) && (rowIndex > this.DataGridView.FirstDisplayedScrollingRowIndex))
                    {
                        useRowShortcut = this.GetRowsHeightExceedLimit(DataGridViewElementStates.Visible, 0, rowIndex, this.DataGridView.LayoutInfo.Data.Height + this.DataGridView.VerticalScrollingOffset) && (height <= this.DataGridView.LayoutInfo.Data.Height);
                    }
                }
            }
            else
            {
                this.DataGridView.OnAddedRow_PreNotification(rowIndex);
                if (!useRowShortcut)
                {
                    int num3 = (this.GetRowsHeight(DataGridViewElementStates.Visible) - this.DataGridView.VerticalScrollingOffset) - dataGridViewRow.GetHeight(rowIndex);
                    dataGridViewRow = this.SharedRow(rowIndex);
                    useRowShortcut = (this.DataGridView.LayoutInfo.Data.Height < num3) && (height <= this.DataGridView.LayoutInfo.Data.Height);
                }
            }
        Label_02DF:
            this.DataGridView.ResetUIState(useRowShortcut, computeVisibleRows);
        }
コード例 #4
0
        private void OnCollectionChanged_PreNotification(CollectionChangeAction cca, 
                                                         int rowIndex,
                                                         int rowCount,
                                                         ref DataGridViewRow dataGridViewRow, 
                                                         bool changeIsInsertion)
        {
            Debug.Assert(this.DataGridView != null);
            bool useRowShortcut = false;
            bool computeVisibleRows = false;
            switch (cca)
            {
                case CollectionChangeAction.Add:
                {
                    int firstDisplayedRowHeight = 0;
                    UpdateRowCaches(rowIndex, ref dataGridViewRow, true);
                    if ((GetRowState(rowIndex) & DataGridViewElementStates.Visible) == 0)
                    {
                        // Adding an invisible row - no need for repaint
                        useRowShortcut = true;
                        computeVisibleRows = changeIsInsertion;
                    }
                    else
                    {
                        int firstDisplayedRowIndex = this.DataGridView.FirstDisplayedRowIndex;
                        if (firstDisplayedRowIndex != -1)
                        {
                            firstDisplayedRowHeight = SharedRow(firstDisplayedRowIndex).GetHeight(firstDisplayedRowIndex);
                        }
                    }
                    if (changeIsInsertion)
                    {
                        this.DataGridView.OnInsertedRow_PreNotification(rowIndex, 1);
                        if (!useRowShortcut)
                        {
                            if ((GetRowState(rowIndex) & DataGridViewElementStates.Frozen) != 0)
                            {
                                // Inserted row is frozen
                                useRowShortcut = this.DataGridView.FirstDisplayedScrollingRowIndex == -1 && 
                                                 GetRowsHeightExceedLimit(DataGridViewElementStates.Visible, 0, rowIndex, this.DataGridView.LayoutInfo.Data.Height);
                            }
                            else if (this.DataGridView.FirstDisplayedScrollingRowIndex != -1 &&
                                     rowIndex > this.DataGridView.FirstDisplayedScrollingRowIndex)
                            {
                                useRowShortcut = GetRowsHeightExceedLimit(DataGridViewElementStates.Visible, 0, rowIndex, this.DataGridView.LayoutInfo.Data.Height + this.DataGridView.VerticalScrollingOffset) &&
                                                 firstDisplayedRowHeight <= this.DataGridView.LayoutInfo.Data.Height;
                            }
                        }
                    }
                    else
                    {
                        this.DataGridView.OnAddedRow_PreNotification(rowIndex);
                        if (!useRowShortcut)
                        {
                            int displayedRowsHeightBeforeAddition = GetRowsHeight(DataGridViewElementStates.Visible) - this.DataGridView.VerticalScrollingOffset - dataGridViewRow.GetHeight(rowIndex);
                            dataGridViewRow = SharedRow(rowIndex);
                            useRowShortcut = this.DataGridView.LayoutInfo.Data.Height < displayedRowsHeightBeforeAddition &&
                                             firstDisplayedRowHeight <= this.DataGridView.LayoutInfo.Data.Height;
                        }
                    }
                    break;
                }

                case CollectionChangeAction.Remove:
                {
                    Debug.Assert(rowCount == 1);
                    DataGridViewElementStates rowStates = GetRowState(rowIndex);
                    bool deletedRowVisible = (rowStates & DataGridViewElementStates.Visible) != 0;
                    bool deletedRowFrozen = (rowStates & DataGridViewElementStates.Frozen) != 0;

                    // Can't do this earlier since it would break UpdateRowCaches
                    this.rowStates.RemoveAt(rowIndex);
                    this.SharedList.RemoveAt(rowIndex);
#if DEBUG
                    this.DataGridView.dataStoreAccessAllowed = false;
#endif
                    this.DataGridView.OnRemovedRow_PreNotification(rowIndex);
                    if (deletedRowVisible)
                    {
                        if (deletedRowFrozen)
                        {
                            // Delete row is frozen
                            useRowShortcut = this.DataGridView.FirstDisplayedScrollingRowIndex == -1 &&
                                             GetRowsHeightExceedLimit(DataGridViewElementStates.Visible, 0, rowIndex, this.DataGridView.LayoutInfo.Data.Height + SystemInformation.HorizontalScrollBarHeight);
                        }
                        else if (this.DataGridView.FirstDisplayedScrollingRowIndex != -1 &&
                                 rowIndex > this.DataGridView.FirstDisplayedScrollingRowIndex)
                        {
                            int firstDisplayedRowHeight = 0;
                            int firstDisplayedRowIndex = this.DataGridView.FirstDisplayedRowIndex;
                            if (firstDisplayedRowIndex != -1)
                            {
                                firstDisplayedRowHeight = SharedRow(firstDisplayedRowIndex).GetHeight(firstDisplayedRowIndex);
                            }
                            useRowShortcut = GetRowsHeightExceedLimit(DataGridViewElementStates.Visible, 0, rowIndex, this.DataGridView.LayoutInfo.Data.Height + this.DataGridView.VerticalScrollingOffset + SystemInformation.HorizontalScrollBarHeight) &&
                                             firstDisplayedRowHeight <= this.DataGridView.LayoutInfo.Data.Height;
                        }
                    }
                    else
                    {
                        // Deleting an invisible row - no need for repaint
                        useRowShortcut = true;
                    }
                    break;
                }

                case CollectionChangeAction.Refresh:
                {
                    InvalidateCachedRowCounts();
                    InvalidateCachedRowsHeights();
                    break;
                }

                default:
                {
                    Debug.Fail("Unexpected cca value in DataGridViewRowCollecttion.OnCollectionChanged");
                    break;
                }
            }
            this.DataGridView.ResetUIState(useRowShortcut, computeVisibleRows);
        }