示例#1
0
		protected virtual void OnCellStyleContentChanged (DataGridViewCellStyleContentChangedEventArgs e) {
			DataGridViewCellStyleContentChangedEventHandler eh = (DataGridViewCellStyleContentChangedEventHandler)(Events [CellStyleContentChangedEvent]);
			if (eh != null)
				eh (this, e);
		}
        internal void OnCellStyleContentChanged(DataGridViewCellStyle dataGridViewCellStyle, DataGridViewCellStyle.DataGridViewCellStylePropertyInternal property)
        {
            Debug.Assert(dataGridViewCellStyle != null);
            switch (property)
            {
                case DataGridViewCellStyle.DataGridViewCellStylePropertyInternal.Font:
                    if ((dataGridViewCellStyle.Scope & DataGridViewCellStyleScopes.DataGridView) != 0 && this.dataGridViewState1[DATAGRIDVIEWSTATE1_ambientFont])
                    {
                        this.dataGridViewState1[DATAGRIDVIEWSTATE1_ambientFont] = false;
                    }
                    if ((dataGridViewCellStyle.Scope & DataGridViewCellStyleScopes.ColumnHeaders) != 0 && this.dataGridViewState1[DATAGRIDVIEWSTATE1_ambientColumnHeadersFont])
                    {
                        this.dataGridViewState1[DATAGRIDVIEWSTATE1_ambientColumnHeadersFont] = false;
                    }
                    if ((dataGridViewCellStyle.Scope & DataGridViewCellStyleScopes.RowHeaders) != 0 && this.dataGridViewState1[DATAGRIDVIEWSTATE1_ambientRowHeadersFont])
                    {
                        this.dataGridViewState1[DATAGRIDVIEWSTATE1_ambientRowHeadersFont] = false;
                    }
                    break;

                case DataGridViewCellStyle.DataGridViewCellStylePropertyInternal.ForeColor:
                    if ((dataGridViewCellStyle.Scope & DataGridViewCellStyleScopes.DataGridView) != 0 && this.dataGridViewState1[DATAGRIDVIEWSTATE1_ambientForeColor])
                    {
                        this.dataGridViewState1[DATAGRIDVIEWSTATE1_ambientForeColor] = false;
                    }
                    break;
            }

            DataGridViewCellStyleContentChangedEventArgs dgvcscce = new DataGridViewCellStyleContentChangedEventArgs(dataGridViewCellStyle,
                property != DataGridViewCellStyle.DataGridViewCellStylePropertyInternal.Color &&
                property != DataGridViewCellStyle.DataGridViewCellStylePropertyInternal.ForeColor /*changeAffectsPreferredSize*/);
            OnCellStyleContentChanged(dgvcscce);
        }
        /// <include file='doc\DataGridView.uex' path='docs/doc[@for="DataGridView.OnCellStyleContentChanged"]/*' />
        protected virtual void OnCellStyleContentChanged(DataGridViewCellStyleContentChangedEventArgs e)
        {
            // We assume that when a color changes, it has no effect on the autosize of elements
            bool repositionEditingControl = false;

            if ((e.CellStyleScope & DataGridViewCellStyleScopes.Cell) == DataGridViewCellStyleScopes.Cell && (e.CellStyleScope & DataGridViewCellStyleScopes.DataGridView) == 0)
            {
                // Same processing as in OnDefaultCellStyleChanged
                if (e.ChangeAffectsPreferredSize)
                {
                    repositionEditingControl = true;
                    OnGlobalAutoSize();
                }
                else
                {
                    Invalidate();
                }
            }

            if ((e.CellStyleScope & DataGridViewCellStyleScopes.Column) == DataGridViewCellStyleScopes.Column)
            {
                if (e.ChangeAffectsPreferredSize)
                {
                    repositionEditingControl = true;
                    OnColumnsGlobalAutoSize();
                }
                else
                {
                    InvalidateData();
                }
            }

            if ((e.CellStyleScope & DataGridViewCellStyleScopes.Row) == DataGridViewCellStyleScopes.Row && (e.CellStyleScope & DataGridViewCellStyleScopes.Rows) == 0 && (e.CellStyleScope & DataGridViewCellStyleScopes.AlternatingRows) == 0)
            {
                // Same processing as in OnRowsDefaultCellStyleChanged
                InvalidateData();
                if (e.ChangeAffectsPreferredSize)
                {
                    repositionEditingControl = true;
                    // Autosize rows if needed
                    if ((((DataGridViewAutoSizeRowsModeInternal)this.autoSizeRowsMode) & DataGridViewAutoSizeRowsModeInternal.AllColumns) != 0)
                    {
                        AdjustShrinkingRows(this.autoSizeRowsMode, false /*fixedWidth*/, true /*internalAutosizing*/);
                    }
                    // Auto size columms also if needed
                    // Impossible to figure out if DisplayedRows filter should be added or not. Adding it to be on the conservative side.
                    AutoResizeAllVisibleColumnsInternal(DataGridViewAutoSizeColumnCriteriaInternal.AllRows |
                                                        DataGridViewAutoSizeColumnCriteriaInternal.DisplayedRows,
                                                        true /*fixedHeight*/);
                    // Second round of rows autosizing
                    if ((((DataGridViewAutoSizeRowsModeInternal)this.autoSizeRowsMode) & DataGridViewAutoSizeRowsModeInternal.AllColumns) != 0)
                    {
                        AdjustShrinkingRows(this.autoSizeRowsMode, true /*fixedWidth*/, true /*internalAutosizing*/);
                    }
                }
            }

            if ((e.CellStyleScope & DataGridViewCellStyleScopes.DataGridView) == DataGridViewCellStyleScopes.DataGridView)
            {
                this.CellStyleChangedEventArgs.ChangeAffectsPreferredSize = e.ChangeAffectsPreferredSize;
                if (e.ChangeAffectsPreferredSize)
                {
                    repositionEditingControl = false;
                    // OnDefaultCellStyleChanged will reposition the editing control.
                }
                OnDefaultCellStyleChanged(this.CellStyleChangedEventArgs);
            }

            if ((e.CellStyleScope & DataGridViewCellStyleScopes.ColumnHeaders) == DataGridViewCellStyleScopes.ColumnHeaders)
            {
                this.CellStyleChangedEventArgs.ChangeAffectsPreferredSize = e.ChangeAffectsPreferredSize;
                if (e.ChangeAffectsPreferredSize)
                {
                    repositionEditingControl = false;
                    // OnColumnHeadersDefaultCellStyleChanged will reposition the editing control.
                }
                OnColumnHeadersDefaultCellStyleChanged(this.CellStyleChangedEventArgs);
            }

            if ((e.CellStyleScope & DataGridViewCellStyleScopes.RowHeaders) == DataGridViewCellStyleScopes.RowHeaders)
            {
                this.CellStyleChangedEventArgs.ChangeAffectsPreferredSize = e.ChangeAffectsPreferredSize;
                if (e.ChangeAffectsPreferredSize)
                {
                    repositionEditingControl = false;
                    // OnRowHeadersDefaultCellStyleChanged will reposition the editing control.
                }
                OnRowHeadersDefaultCellStyleChanged(this.CellStyleChangedEventArgs);
            }

            if ((e.CellStyleScope & DataGridViewCellStyleScopes.Rows) == DataGridViewCellStyleScopes.Rows)
            {
                this.CellStyleChangedEventArgs.ChangeAffectsPreferredSize = e.ChangeAffectsPreferredSize;
                if (e.ChangeAffectsPreferredSize)
                {
                    repositionEditingControl = false;
                    // OnRowsDefaultCellStyleChanged will reposition the editing control.
                }
                OnRowsDefaultCellStyleChanged(this.CellStyleChangedEventArgs);
            }

            if ((e.CellStyleScope & DataGridViewCellStyleScopes.AlternatingRows) == DataGridViewCellStyleScopes.AlternatingRows)
            {
                this.CellStyleChangedEventArgs.ChangeAffectsPreferredSize = e.ChangeAffectsPreferredSize;
                if (e.ChangeAffectsPreferredSize)
                {
                    repositionEditingControl = false;
                    // OnAlternatingRowsDefaultCellStyleChanged will reposition the editing control.
                }
                OnAlternatingRowsDefaultCellStyleChanged(this.CellStyleChangedEventArgs);
            }

            if (repositionEditingControl && this.editingControl != null)
            {
                PositionEditingControl(true /*setLocation*/, true /*setSize*/, false /*setFocus*/);
            }

            DataGridViewCellStyleContentChangedEventHandler eh = this.Events[EVENT_DATAGRIDVIEWCELLSTYLECONTENTCHANGED] as DataGridViewCellStyleContentChangedEventHandler;
            if (eh != null && !this.dataGridViewOper[DATAGRIDVIEWOPER_inDispose] && !this.IsDisposed)
            {
                eh(this, e);
            }
        }
 protected virtual void OnCellStyleContentChanged(DataGridViewCellStyleContentChangedEventArgs e);
示例#5
0
 private void dgvItem_CellStyleContentChanged(object sender, DataGridViewCellStyleContentChangedEventArgs e)
 {
     txtPrice.Text = SumTotalPrice().ToString();
     txtSumTotal.Text = SumTotal().ToString();
     txtCount.Text = SumTotalCount().ToString();
 }
        internal void OnCellStyleContentChanged(DataGridViewCellStyle dataGridViewCellStyle, DataGridViewCellStyle.DataGridViewCellStylePropertyInternal property)
        {
            switch (property)
            {
                case DataGridViewCellStyle.DataGridViewCellStylePropertyInternal.Font:
                    if (((dataGridViewCellStyle.Scope & DataGridViewCellStyleScopes.DataGridView) != DataGridViewCellStyleScopes.None) && this.dataGridViewState1[0x2000000])
                    {
                        this.dataGridViewState1[0x2000000] = false;
                    }
                    if (((dataGridViewCellStyle.Scope & DataGridViewCellStyleScopes.ColumnHeaders) != DataGridViewCellStyleScopes.None) && this.dataGridViewState1[0x4000000])
                    {
                        this.dataGridViewState1[0x4000000] = false;
                    }
                    if (((dataGridViewCellStyle.Scope & DataGridViewCellStyleScopes.RowHeaders) != DataGridViewCellStyleScopes.None) && this.dataGridViewState1[0x8000000])
                    {
                        this.dataGridViewState1[0x8000000] = false;
                    }
                    break;

                case DataGridViewCellStyle.DataGridViewCellStylePropertyInternal.ForeColor:
                    if (((dataGridViewCellStyle.Scope & DataGridViewCellStyleScopes.DataGridView) != DataGridViewCellStyleScopes.None) && this.dataGridViewState1[0x400])
                    {
                        this.dataGridViewState1[0x400] = false;
                    }
                    break;
            }
            DataGridViewCellStyleContentChangedEventArgs e = new DataGridViewCellStyleContentChangedEventArgs(dataGridViewCellStyle, (property != DataGridViewCellStyle.DataGridViewCellStylePropertyInternal.Color) && (property != DataGridViewCellStyle.DataGridViewCellStylePropertyInternal.ForeColor));
            this.OnCellStyleContentChanged(e);
        }
 protected virtual void OnCellStyleContentChanged(DataGridViewCellStyleContentChangedEventArgs e)
 {
     bool flag = false;
     if (((e.CellStyleScope & DataGridViewCellStyleScopes.Cell) == DataGridViewCellStyleScopes.Cell) && ((e.CellStyleScope & DataGridViewCellStyleScopes.DataGridView) == DataGridViewCellStyleScopes.None))
     {
         if (e.ChangeAffectsPreferredSize)
         {
             flag = true;
             this.OnGlobalAutoSize();
         }
         else
         {
             base.Invalidate();
         }
     }
     if ((e.CellStyleScope & DataGridViewCellStyleScopes.Column) == DataGridViewCellStyleScopes.Column)
     {
         if (e.ChangeAffectsPreferredSize)
         {
             flag = true;
             this.OnColumnsGlobalAutoSize();
         }
         else
         {
             this.InvalidateData();
         }
     }
     if ((((e.CellStyleScope & DataGridViewCellStyleScopes.Row) == DataGridViewCellStyleScopes.Row) && ((e.CellStyleScope & DataGridViewCellStyleScopes.Rows) == DataGridViewCellStyleScopes.None)) && ((e.CellStyleScope & DataGridViewCellStyleScopes.AlternatingRows) == DataGridViewCellStyleScopes.None))
     {
         this.InvalidateData();
         if (e.ChangeAffectsPreferredSize)
         {
             flag = true;
             if ((this.autoSizeRowsMode & ((DataGridViewAutoSizeRowsMode) 2)) != DataGridViewAutoSizeRowsMode.None)
             {
                 this.AdjustShrinkingRows(this.autoSizeRowsMode, false, true);
             }
             this.AutoResizeAllVisibleColumnsInternal(DataGridViewAutoSizeColumnCriteriaInternal.DisplayedRows | DataGridViewAutoSizeColumnCriteriaInternal.AllRows, true);
             if ((this.autoSizeRowsMode & ((DataGridViewAutoSizeRowsMode) 2)) != DataGridViewAutoSizeRowsMode.None)
             {
                 this.AdjustShrinkingRows(this.autoSizeRowsMode, true, true);
             }
         }
     }
     if ((e.CellStyleScope & DataGridViewCellStyleScopes.DataGridView) == DataGridViewCellStyleScopes.DataGridView)
     {
         this.CellStyleChangedEventArgs.ChangeAffectsPreferredSize = e.ChangeAffectsPreferredSize;
         if (e.ChangeAffectsPreferredSize)
         {
             flag = false;
         }
         this.OnDefaultCellStyleChanged(this.CellStyleChangedEventArgs);
     }
     if ((e.CellStyleScope & DataGridViewCellStyleScopes.ColumnHeaders) == DataGridViewCellStyleScopes.ColumnHeaders)
     {
         this.CellStyleChangedEventArgs.ChangeAffectsPreferredSize = e.ChangeAffectsPreferredSize;
         if (e.ChangeAffectsPreferredSize)
         {
             flag = false;
         }
         this.OnColumnHeadersDefaultCellStyleChanged(this.CellStyleChangedEventArgs);
     }
     if ((e.CellStyleScope & DataGridViewCellStyleScopes.RowHeaders) == DataGridViewCellStyleScopes.RowHeaders)
     {
         this.CellStyleChangedEventArgs.ChangeAffectsPreferredSize = e.ChangeAffectsPreferredSize;
         if (e.ChangeAffectsPreferredSize)
         {
             flag = false;
         }
         this.OnRowHeadersDefaultCellStyleChanged(this.CellStyleChangedEventArgs);
     }
     if ((e.CellStyleScope & DataGridViewCellStyleScopes.Rows) == DataGridViewCellStyleScopes.Rows)
     {
         this.CellStyleChangedEventArgs.ChangeAffectsPreferredSize = e.ChangeAffectsPreferredSize;
         if (e.ChangeAffectsPreferredSize)
         {
             flag = false;
         }
         this.OnRowsDefaultCellStyleChanged(this.CellStyleChangedEventArgs);
     }
     if ((e.CellStyleScope & DataGridViewCellStyleScopes.AlternatingRows) == DataGridViewCellStyleScopes.AlternatingRows)
     {
         this.CellStyleChangedEventArgs.ChangeAffectsPreferredSize = e.ChangeAffectsPreferredSize;
         if (e.ChangeAffectsPreferredSize)
         {
             flag = false;
         }
         this.OnAlternatingRowsDefaultCellStyleChanged(this.CellStyleChangedEventArgs);
     }
     if (flag && (this.editingControl != null))
     {
         this.PositionEditingControl(true, true, false);
     }
     DataGridViewCellStyleContentChangedEventHandler handler = base.Events[EVENT_DATAGRIDVIEWCELLSTYLECONTENTCHANGED] as DataGridViewCellStyleContentChangedEventHandler;
     if (((handler != null) && !this.dataGridViewOper[0x100000]) && !base.IsDisposed)
     {
         handler(this, e);
     }
 }
        /// <summary>
        /// Extends BeginInvoke so that when a state object is not needed, null does not need to be passed.
        /// <example>
        /// datagridviewcellstylecontentchangedeventhandler.BeginInvoke(sender, e, callback);
        /// </example>
        /// </summary>
        public static IAsyncResult BeginInvoke(this DataGridViewCellStyleContentChangedEventHandler datagridviewcellstylecontentchangedeventhandler, Object sender, DataGridViewCellStyleContentChangedEventArgs e, AsyncCallback callback)
        {
            if(datagridviewcellstylecontentchangedeventhandler == null) throw new ArgumentNullException("datagridviewcellstylecontentchangedeventhandler");

            return datagridviewcellstylecontentchangedeventhandler.BeginInvoke(sender, e, callback, null);
        }