This sample demonstrates how to create a custom DataGridView column.
There are six standard DataGridViewColumn types for use as follows:
- DataGridViewTextBoxColumn
- DataGridViewCheckedBoxColumn
- DataGridViewComboBoxColumn
- DataGridViewLinkColumn
- DataGridViewButtonColumn
- DataGridViewImageColumn
However, developers may want to use a different control for editing on the column, e.g. MarkedTextBox, DateTimePicker etc. This feature can be achieved in two ways:
-
Create a custom DataGridViewColumn;
The code in this CustomDataGridViewColumn sample demonstrates how to do this.
-
Place the editing control on the current cell when editing begins, and hide the editing control when the editing completes. For the details of this approach, please refer to the EditingControlHosting sample.
-
Create a MaskedTextBoxEditingControl class derive from MaskedTextBox class and IDataGridViewEditingControl class, see the code in the MaskedTextBoxEditingControl.cs file for the implementation details.
-
Create a MaskedTextBoxCell class derive from DataGridViewTextBoxCell class, see the code in the MaskedTextBoxCell.cs file for the implementation details.
-
Create a MaskedTextBoxColumn class derive from DataGridViewColumn class, see the code in the MaskedTextBoxColumn.cs file for the implementation details.
-
Build the program.