Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

c#

focus

winforms

I have a DataGridView component on a form. How do I set the focus to this component so that it responds to arrow keys?

like image 662
Craig Johnston Avatar asked Dec 10 '22 10:12

Craig Johnston


1 Answers

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.

like image 112
Fun Mun Pieng Avatar answered May 22 '23 10:05

Fun Mun Pieng