开发者

C# Winforms: how do you set focus to a DataGridView component on a form?

开发者 https://www.devze.com 2023-02-16 16:59 出处:网络
I have a DataGridView component on a form.How do I set the focus to this component so that it responds to a开发者_开发问答rrow keys?You could:

I have a DataGridView component on a form. How do I set the focus to this component so that it responds to a开发者_开发问答rrow keys?


You could:

dataGridView.Select();

or

dataGridView.Focus();

Alternatively, you could set the ActiveControl property:

ActiveControl = dataGridView;

The following text came from Microsoft

Focus is a low-level method intended primarily for custom control authors. Instead, application programmers should use the Select method or the ActiveControl property for child controls, or the Activate method for forms.


U can try with this.

public void SetFocusToDataEntry() 

{
_datagridview.Focus();
_datagridview.CurrentCell = _datagridview.Rows[1].Cells[2];
}
0

精彩评论

暂无评论...
验证码 换一张
取 消