Validate Cell Value in Datagridview
-
Tuesday, December 12, 2006 9:11 PM
Hi
I have a datagridview where i manualy add rows and columns. But when the user tabs out of a specific cell i need to get the value and do a check. But i get blank.
I'm using the following
dgrdvGLTransLines.CellValidating +=
new DataGridViewCellValidatingEventHandler(dgrdvGLTransLines_CellValidating); private void dgrdvGLTransLines_CellValidating(object sender, DataGridViewCellValidatingEventArgs e){
if (e.ColumnIndex == 0){
string s=Convert.ToString(dgrdvGLTransLines.Rows[e.RowIndex ].Cells[e.ColumnIndex ].Value);}
}
It returns a blank value if i exit out of a cell i just typed in. If i click on that cell again, retype something else then tab out the cell i then get the first value and not the retyped value. Basically it seems it's checking the cell value before the cell has assigned itself the new value.
How can i get around this??? When i tab out the cell i want the latest value.
Thanks in advance

All Replies
-
Friday, December 15, 2006 5:07 AM
Hi,
Here's the sample on msdn: (http://msdn2.microsoft.com/en-us/library/system.windows.forms.datagridview.cellvalidating.aspx)
private void dataGridView1_CellValidating(object sender, DataGridViewCellValidatingEventArgs e) { dataGridView1.Rows[e.RowIndex].ErrorText = ""; int newInteger; // Don't try to validate the 'new row' until finished // editing since there // is not any point in validating its initial value. if (dataGridView1.Rows[e.RowIndex].IsNewRow) { return; } if (!int.TryParse(e.FormattedValue.ToString(), out newInteger) || newInteger < 0) { e.Cancel = true; dataGridView1.Rows[e.RowIndex].ErrorText = "the value must be a non-negative integer"; } }
Maybe the behavior you see is because you are validating a new row?
Charles
-
Tuesday, August 28, 2012 8:25 PMHi also try this for compare value in specific range..http://codingresolved.com/discussion/75/how-to-validate-and-compare-datagridview-cell-value-in-c


