RE: Different datatype in different rows

Tech-Archive recommends: Fix windows errors by optimizing your registry



Hi Paul,

Thank you for your reply!

In which eventhandler would you do it - I tried the RowsAdded but I've
seen that the first couple of rows added are empty

I mean you can add rows to the DataGridView when the form is loaded or when
you click a Button.
What do you mean by "the first couple of rows added are empty"?

Can you point me to any samples showing how to restrict the input in a
cell of type double.

You can subscribe the CellValidating event of the DataGridView and in the
event handler use the double.TryParse method to validate the input. For
example:

void dataGridView1_CellValidating(object sender,
DataGridViewCellValidatingEventArgs e)
{
double result;
bool isValid = double.TryParse(e.FormattedValue.ToString(), out
result);
if (!isValid)
{
e.Cancel = true;
}
}

Hope this helps.
If you have any question, please feel free to let me know.

Sincerely,
Linda Liu
Microsoft Online Community Support

.


Quantcast