当前位置: 动力学知识库 > 问答 > 编程问答 >

c# - Focus next control when pressing 'TAB' key

问题描述:

I have a DataGridView where I manage manually the focused cells when navigating with Tab key. For example, when the first cell from the last row is the last cell than can be navigated in the DataGridView I want that when pressing Tab the focus to go on the next focusable control (a button).

SendKeys.Send("{TAB}") will not work - the focus will go to the second cell on the last row

网友答案:

Have you tried the SelectNextControl method?

网友答案:

If you set the StandardTab property to True then the behavior of the Tab key will change from moving to the next grid cell to moving to the next control on the form. This may be what you want.

If you want to control which grid cell/column/row gets focused then you can handle the ProcessDialogKey and ProcessDataGridViewKey events in your code.

网友答案:

Like Rune Grimstad said, if you want any tab behavior other than the one provided by default or StandardTab, you will have to implement your own 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;
}
网友答案:
Control nextControl = this.dataGridView1.Parent.GetNextControl(this.dataGridView1, true);
Control prevControl = this.dataGridView1.Parent.GetNextControl(this.dataGridView1, false);
网友答案:

You can just simply use the DataGridView's StandardTab property.

dataGridView1.StandardTab = true;

Note that user can do this with non StandardTab with CTRL +TAB combination, StandardTab reverses this behaviour.

分享给朋友:
您可能感兴趣的文章:
随机阅读: