Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to control SendKeys.Send{"tab"} property in Datagridview?

I am writing the code in datagridview cell enter event as

private void dgvGoodsRecpt_CellEnter(object sender, DataGridViewCellEventArgs e)
{
    if (dgvGoodsRecpt.CurrentRow.Cells[e.ColumnIndex].ReadOnly)
    {
        SendKeys.Send("{tab}");
    }
}

This code will send the tab to next cell ,if the current cell is ReadOnly true.

It is working well but here my problem is that my datagridview last column is readonly true and the next controls are txtAmount1.Text and txtAmount2.Text.

When I keep on pressing Tab key the focus is going to txtAmount2.Text. But the next to datagridview is txtAmount1.Text. The focus is going to the next control of the imidiate control after datagridview. The focus supposed to go to the txtAmount1.Text control. What should I do? Please help me.

like image 569
Learner Avatar asked Oct 21 '22 17:10

Learner


1 Answers

There is a list of predefined string constants for non-alphanumeric keys. For example, {TAB} is for a Tab key. Here is MSDN article with all constants: https://msdn.microsoft.com/en-us/library/system.windows.forms.sendkeys.send%28v=vs.110%29.aspx?f=255&MSPPError=-2147217396

You may also consider using SendKeys.SendWait instead. This method will ensure that target application processes sent key before your application continues. For example:

SendKeys.SendWait("{TAB}");
like image 198
zmechanic Avatar answered Nov 01 '22 08:11

zmechanic