I have a grid in a user control where its not possible to set the grid to be the first tab index.
Whats the best way to programatically set the focus to the grid?Should it just be .Focus() ?Will this make the grid have an active row?
I presume I can't set the focus in OnLoad as not everything is visible yet.Theres no Activated for usercontrols.
Hi jaa,
Definetly you can set the Active Row in the Load event provided the grid is provided with datasource...(Runtime or Desingntme)
if ur providing the datasource at designtime.. then it will be ready before the load event,, so u can set it
best part wud be if ur providing a datasource at runtime ,immediate next line of code check for the row count and set the activerow to row(0) index.
hope this helps you ..
hppy Koding,
Arun
If you are using CLR2, then you can probably use the Form_Shown event. Otherwise, you might be able to set focus to the grid in the Form_Load by using a BeginInvoke instead of calling it directly.
However, I'm not sure why you can't set the TabIndex to 0. If the grid is inside a UserControl, then I expect that setting the grid's tabIndex to 0 inside the UserControl and setting the UserControls TabIndex to 0 on the form would ensure that the grid has focus when the form loads.
Seting focus to the grid probably isn't enough, though. You probably want to set the ActiveCell and then call PerformAction(EnterEditMode) to allow the user to start typing immediately.