Datagrid validation..

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • buterfly0707
    New Member
    • Nov 2009
    • 30

    Datagrid validation..

    hi..

    i want to check weather datagrid particular cell is empty. whet i wan to 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

    Code:
                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
Working...