punctual any doubts of a partner, write this very simple and timely post dedicated to showing the way in which to validate a cell in a DataGridView (in this case is VisualStudio2005) of course the code is very trivial and is written in C #. To show how to solve this situation we have a DataGridView (DataGridView1), which has two columns Name and ID cells are editable and we want to validate is that only you can enter an integer value of TIMP in the cells corresponding to the ID column. Here we see the form with the DataGridView control:
And here's the code that performs the validation, the event used as we see the CellValidating the DataGridView: private
Solved the problem, I hope to publish my post and to serve those who read it. Good weekend to all!
dataGridView1_CellValidating void ( object sender , DataGridViewCellValidatingEventArgs e )
{
int testInt ;
if ( e . ColumnIndex == 1 )
{
if ( e . FormattedValue . ToString (). Length != 0 )
{
if (! int . TryParse ( and . FormattedValue . ToString (), October testInt )) {
DataGridView1 . Rows [ and . RowIndex ]. ErrorText = "identity card must be a number" ;
e . Cancel = true ;
}
else
{
dataGridView1 . Rows [ e . RowIndex ]. ErrorText = string . Empty ;
e . Cancel = false ;
}}
}}}
0 comments:
Post a Comment