Click here to Skip to main content
15,913,214 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
How to check data inputed by the user in the DataGrid.
the DataGrid looks like this:

+-----------------------------------+
| ID | Grade |
+-----------------------------------+
| 1 | 1.3 |
| 2 | 3.2 |
| 3 | 3.5 |
+-----------------------------------+

If there is a grade of greater than 3.1 then it will not save,
if there is no greater then 3.1 then it will save.

Please help.

I couldn't solve it.

Thanks in advanced.
Posted
Updated 8-Feb-11 17:04pm
v2

I do not understand You want to how to input data.If you input by textbox, You can check data input in textbox else if you input directly in grid, before update you use for loop to check cell that it contain thing you want to check or access to cell that you want to check.

good lucky!
 
Share this answer
 
Comments
Dalek Dave 10-Feb-11 4:23am    
Seems reasonable.
Try this:
C#
private void dataGridView1_CellValueChanged(object sender, DataGridViewCellEventArgs e)
{
  if (e.ColumnIndex >=0 && e.RowIndex >=0)
  {
    if (dataGridView1.Rows[e.RowIndex].Cells[e.ColumnIndex].Value != null)
    {
      if (dataGridView1.Rows[e.RowIndex].Cells[e.ColumnIndex].Value.ToString() != "")
      {
        if (float.Parse(dataGridView1.Rows[e.RowIndex].Cells[e.ColumnIndex].Value.ToString()) > 3.1)
        {                             
          dataGridView1.Rows[e.RowIndex].Cells[e.ColumnIndex].Value = null;
        }
      }
    }
  }
}
 
Share this answer
 
v3
Comments
JF2015 10-Feb-11 4:20am    
Added code formatting.
Dalek Dave 10-Feb-11 4:24am    
That's a lot of nessting.
There is a more elegant way of expressing it.
is this is desktop application or in web application
 
Share this answer
 
Comments
jleonorlane 8-Feb-11 23:14pm    
a desktop app

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900