I have a gridview of type datagridview text box column, in that following columns are there:
SrNo | Description | HSNCode | Qty | Rate | Amount
I am generating amount in my program automatically, but I want to check if the user has entered to amount field without entering data in "Rate" then I want to set focus back to the "Rate" field in my program:
I have tried following code:
private void grdData_CellLeave(object sender, DataGridViewCellEventArgs e)
{
if (e.ColumnIndex == 4)
{
if(grdData.Rows[e.RowIndex].Cells[4].Value== null)
{
grdData.CurrentCell = grdData.Rows[e.RowIndex].Cells[4];
}
}
}
But the code is not working.
What should I do to switch focus to the field that is previous to the "Amount"?
Please help.
Try:
Update - tested and working fine using
cellclick
eventRefer following code:
For more assistance, you can follow discussion in following link:
http://www.vbdotnetforums.com/winforms-grids/11313-setting-cell-focus-datagridview.html
Hope its helpful.
You can try this piece of code