[英]Focus not setting on DataGridView on Button Preview KeyDown Event
在Button Refresh上按Tab鍵可將焦點設置在下拉列表上,但是當網格數據源不為null時,我需要將焦點設置在Checkbox列和網格的第一行,否則下一個控件將被設置為焦點。 我已經按順序設置了tabIndex屬性,請告訴我哪里錯了,這是我的代碼:
private void btnRefresh_PreviewKeyDown(object sender, PreviewKeyDownEventArgs e)
{
if (e.KeyCode == Keys.Tab)
{
if (grid.DataSource != null)
{
grid.Focus();
grid.CurrentCell = this.grid[1, 0];
grid.CurrentCell.Selected = true;
grid.BeginEdit(false);
}
else
{
btnCancel.Focus();
}
}
}
你看過這個帖子嗎? 似乎您對索引的使用是Grid [x,y]。
嘗試
grid.Rows[1].Cells[0]
但是,這只會選擇單元格(順便說一下,第一單元格,第二行)。 如果要選擇整行,請嘗試
grid.Rows.First().Selected = True
希望能幫助到你。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.