I have a DataGridView
control in which I want to restrict the user to entering only numeric values for a cell under a particular column. How can I accomplish this t
You can set the type of data the column will hold as the following code snippet illustrates:
var columnSpec = new DataColumn();
columnSpec.DataType =
// Other initialisation
dataTable.Columns.Add(columnSpec);
dataGridView.DataSource = dataTable;
If you are working directly on the DataGridView
then the DataGridViewColumn
class has the following property:
ValueType - Gets or sets the data type of the values in the column's cells.
If you create your columns using this class rather than the more specialised classes DataGridViewCheckBoxColumn
etc. this might do want you want.