System.Data.DataColumnCollection.Clear C# (CSharp) Method

Clear() public method

Clears the collection of any columns.
public Clear ( ) : void
return void
        public void Clear()
        {
            int oldLength = _list.Count;

            DataColumn[] columns = new DataColumn[_list.Count];
            _list.CopyTo(columns, 0);

            OnCollectionChanging(s_refreshEventArgs);

            if (_table.fInitInProgress && _delayedAddRangeColumns != null)
            {
                _delayedAddRangeColumns = null;
            }

            try
            {
                // this will smartly add and remove the appropriate tables.
                _fInClear = true;
                BaseGroupSwitch(columns, oldLength, null, 0);
                _fInClear = false;
            }
            catch (Exception e) when (ADP.IsCatchableOrSecurityExceptionType(e))
            {
                // something messed up: restore to old values and throw
                _fInClear = false;
                BaseGroupSwitch(null, 0, columns, oldLength);
                _list.Clear();
                for (int i = 0; i < oldLength; i++)
                {
                    _list.Add(columns[i]);
                }
                throw;
            }

            _list.Clear();
            _table.ElementColumnCount = 0;
            OnCollectionChanged(s_refreshEventArgs);
        }

Usage Example

Beispiel #1
0
 private void ResetColumns()
 {
     // this method is used design-time scenarios via reflection
     //   by the property grid context menu to show the Reset option or not
     Columns.Clear();
 }
All Usage Examples Of System.Data.DataColumnCollection::Clear