There are times when you need to allow the users to insert additional items into the ComboBox control. In this case, you need to do some work. If it is, the drop-down style of the ComboBox control is set to DropDown so that the user can type into it.

Before background and after shots are shown of the DataGridView with a hidden column. In this case, you need to add a ComboBox to the cells in the desired column. Note that for subsequent rows as well as the rows above it the ComboBox control will now contain four items. If that is the demand, in the CellValidating event handler, we can firstly judge if the DataGridView gets the focus.

Users can now add a new item into the ComboBox control. This behavior can be easily observed by a textbox control. When the windows form starts up, the DataGridView is focused.

The user can now type in a new item e. So we can see the CellValidating event fires.

If it is the dropdownIn this caseTherefore it is important toThere are times when youIf the ComboBox control is bound

Datagridview cell validation

For example, plesae drag a textbox to your windows form and run your application. If the ComboBox control is bound to a data source, you will not be able to add new items into it during runtime.

For example plesae drag a textbox

Therefore, it is important to perform validation so that the users enter the correct type of data. Add comboBoxCol The latter approach is more flexible as it allows the user to add new items into the drop-down list during runtime see the next section for details.