0

I have a grid view of type data grid view text box column.

There are following fields in the grid.

Sr.No | Description | HSNCode | Qty | Rate | Amount

The Sr.No and the Amount is generated in the program.

My problem is that when I am using tab key for navigating through the grid, I want to check that the is "Qty" and "Rate" contains any value or not.

i.e. if the user enters the description then without entering "Qty" and "Rate" one jumps to the Amount field where I am generating the value by "Qty * Rate" but I want to check if the "Rate" or "Qty" is not entered then I want to transfer the control over either of them.

I have found the solution which works for the mouse click, the code is as below:

private void grdData_CellClick(object sender, DataGridViewCellEventArgs e)
{
    if (e.ColumnIndex == 5)
    {
       if (Convert.ToString(grdData.Rows[e.RowIndex].Cells[4].Value).Equals(""))
       {
           grdData.ClearSelection();
           grdData.Rows[e.RowIndex].Cells[4].Selected = true;
       }
    }
}

This works perfectly when user clicks on the Amount field, but what if I want the same solution for tab key.

How can I find the solution? Which event should I use for grid.?

Please help

Mohemmad K
  • 809
  • 7
  • 33
  • 74

1 Answers1

0

You can try out CellLeave/CellValidating event. I am a little rusty on coding but I believe that's something that can work out for you.

danish
  • 5,550
  • 2
  • 25
  • 28
  • I placed the code of `Cell_Click()` in the `CellLeave()` and `CellValidating()` but not working. – Mohemmad K Apr 16 '13 at 06:18
  • You should not be using row and column index from event args in those methods. Just debug and see whats not correct there. – danish Apr 16 '13 at 06:37