/// <summary> /// Prepares this control to edit the specified column and item. /// </summary> /// <param name="tableColumn"></param> /// <param name="item"></param> internal void BeginEdit(ITableColumn tableColumn, object item) { // remove any previous event subscription if (_editor != null) { _editor.ValueChanged -= ValueChangedEventHandler; } _tableColumn = tableColumn; // get cell editor for this column _editor = tableColumn.GetCellEditor(); _editor.BeginEdit(item); // subscribe to event so we know when cell is dirtied _editor.ValueChanged += ValueChangedEventHandler; // create editor view only once if (_editorView == null) { _editorView = (ITableCellEditorView)ViewFactory.CreateAssociatedView(_editor.GetType()); var control = (Control)_editorView.GuiElement; control.Dock = DockStyle.Fill; this.Controls.Add(control); } // associate view with current editor _editorView.SetEditor(_editor); }
/// <summary> /// Attaches and initializes the hosted editing control. /// </summary> /// <param name="rowIndex">The index of the row being edited.</param><param name="initialFormattedValue">The initial value to be displayed in the control.</param><param name="dataGridViewCellStyle">A cell style that is used to determine the appearance of the hosted control.</param><filterpriority>1</filterpriority><PermissionSet><IPermission class="System.Security.Permissions.EnvironmentPermission, mscorlib, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" version="1" Unrestricted="true"/><IPermission class="System.Security.Permissions.FileIOPermission, mscorlib, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" version="1" Unrestricted="true"/><IPermission class="System.Security.Permissions.SecurityPermission, mscorlib, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" version="1" Flags="UnmanagedCode, ControlEvidence"/><IPermission class="System.Diagnostics.PerformanceCounterPermission, System, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" version="1" Unrestricted="true"/></PermissionSet> public override void InitializeEditingControl( int rowIndex, object initialFormattedValue, DataGridViewCellStyle dataGridViewCellStyle) { // Set the value of the editing control to the current cell value. base.InitializeEditingControl(rowIndex, initialFormattedValue, dataGridViewCellStyle); var editor = _tableColumn.GetCellEditor(); var editControl = DataGridView.EditingControl as CustomTableCellEditControl; if (editControl != null && editor != null) { // notify control that it is about to begin editing this column and item editControl.BeginEdit(_tableColumn, _table.Items[rowIndex]); } }
/// <summary> /// Prepares this control to edit the specified column and item. /// </summary> /// <param name="tableColumn"></param> /// <param name="item"></param> internal void BeginEdit(ITableColumn tableColumn, object item) { // remove any previous event subscription if (_editor != null) { _editor.ValueChanged -= ValueChangedEventHandler; } _tableColumn = tableColumn; // get cell editor for this column _editor = tableColumn.GetCellEditor(); _editor.BeginEdit(item); // subscribe to event so we know when cell is dirtied _editor.ValueChanged += ValueChangedEventHandler; // create editor view only once if (_editorView == null) { _editorView = (ITableCellEditorView)ViewFactory.CreateAssociatedView(_editor.GetType()); var control = (Control) _editorView.GuiElement; control.Dock = DockStyle.Fill; this.Controls.Add(control); } // associate view with current editor _editorView.SetEditor(_editor); }