Focus next control when pressing "TAB" key

I have a DataGridView where I manually control the focused cells when navigating with a key Tab. For example, when the first cell from the last row is the last cell that can be moved in the DataGridView, I want the Tabfocus to go to the next custom control (button) when clicked .

SendKeys.Send ("{TAB}") won't work - focus will go to the second cell of the last line

+1


a source to share


5 answers


Have you tried the SelectNextControl method ?



+2


a source


If you set the property StandardTab

to True, the Tab key behavior changes from moving to the next cell in the cell to moving to the next form element. This might be what you want.



If you want to control which grid cell / column / line will be focused, you can handle events ProcessDialogKey

, and ProcessDataGridViewKey

in your code.

+6


a source


Like Rune Grimstad, if you need any tabulation behavior other than the default or StandardTab provided, you will need to implement your tab behavior.

Create a new class that inherits from DataGridView.

protected override bool ProcessDialogKey(Keys keyData)
{
    case Keys.Tab | Keys.Shift:
        // implement your logic here.
        break;
    case Keys.Tab:
        // implement your logic here.
        break;
}

      

+1


a source


Control nextControl = this.dataGridView1.Parent.GetNextControl(this.dataGridView1, true);
Control prevControl = this.dataGridView1.Parent.GetNextControl(this.dataGridView1, false);

      

0


a source


You can just use the DataGridView StandardTab property .

dataGridView1.StandardTab = true;

      

Note that the user can do this using a custom table with the CTRL+ combination TAB, StandardTab overrides this behavior.

0


a source







All Articles