DataGridViewCell::InitializeEditingControl Method (Int32, Object^, DataGridViewCellStyle^)

 

Initializes the control used to edit the cell.

Namespace:   System.Windows.Forms
Assembly:  System.Windows.Forms (in System.Windows.Forms.dll)

public:
virtual void InitializeEditingControl(
	int rowIndex,
	Object^ initialFormattedValue,
	DataGridViewCellStyle^ dataGridViewCellStyle
)

Parameters

rowIndex
Type: System::Int32

The zero-based row index of the cell's location.

initialFormattedValue
Type: System::Object^

An Object that represents the value displayed by the cell when editing is started.

dataGridViewCellStyle
Type: System.Windows.Forms::DataGridViewCellStyle^

A DataGridViewCellStyle that represents the style of the cell.

Exception Condition
InvalidOperationException

There is no associated DataGridView or if one is present, it does not have an associated editing control.

As an optimization technique, typically all the cells of the same type and in the same DataGridView share a single hosted editing control. However, before the control is used by a cell, it needs to be initialized by the InitializeEditingControl method. The first time it is called, this method adds the control to the list of editing controls in its parent DataGridView. It also initializes some of the visual properties of the cell. For example, InitializeEditingControl sets the background color of the editing area to match the supplied cell style parameter. Subsequent calls to InitializeEditingControl do nothing.

Derived classes use this method to host an instance of the Control class corresponding to their type. For example, a table that contains one or more DataGridViewTextBoxCell objects calls this method to add a single TextBox editing control to the owning DataGridView.

The following code example demonstrates how to override the InitializeEditingControl method in a simple class that derives from the DataGridViewTextBoxCell class. This example is part of a larger code example provided in How to: Host Controls in Windows Forms DataGridView Cells.

No code example is currently available or this language may not be supported.

.NET Framework
Available since 2.0
Return to top
Show: