Click here to Skip to main content
15,896,118 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi..
i want to check weather datagrid particular cell is empty. what i wantto do is :
if in a datagrid row if 1st 2 cells are not null and if i did not enter a value to 3rd cell then i go to enter new values to next row then i want o give error fill the 3rd cell.
so far what i did was:
here dgvItem is my datagrid. i have written this code in cell_enter event

try
             {
                 if (dgvItem.CurrentCell.ColumnIndex == 1)
                 {
                 //for (int i = 0; i < dgvItem.Rows.Count+1; i++)
                // if (dgvItem.CurrentRow.Index==0)
                 //{
  
                     string itemDis;
                     itemDis = Convert.ToString(dgvItem.CurrentRow.Cells[1].Value);
                     //itemDis = Convert.ToString(dgvItem.Rows[i].Cells[1].Value);
                     string itemQty;
                     itemQty = Convert.ToString(dgvItem.CurrentRow.Cells[3].Value);
                     //itemQty = Convert.ToString(dgvItem.Rows[i].Cells[3].Value);
                     if (itemDis != "" && itemQty == "")
                     {
                         DialogResult reply = MessageBox.Show("Please Fill the data", "", MessageBoxButtons.OK, MessageBoxIcon.Error);
                         if (reply == DialogResult.OK)
                         {
                             dgvItem.Focus();
                         }
                     }
                 }
            }
             catch { }


i have tried many ways to do this as i have comment in the code above. but the message is coming when ever i click on the cell.
meaning my 1st cell is a combobox.so when i click on the 2nd cell relevent value for combobox selected value have to fill to 2nd cell. so even when i clik on 2nd cell before even go to next row the message is comming.

so what can i do ?? how can i do this. i hope what im asking is clear over here?

thank you
Posted
Updated 14-Feb-10 18:49pm
v2

1 solution

You should use RowLeave or RowValidating events (depending on your situation and what you want) to perform those checks.
 
Share this answer
 
v2

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