ljcor
asked on
VB 2008 - Focus on a previously Selected row in a DataGridView
Form1 holds the DataGridView control. To set focus for the control, in the Form_Activated event I set the CurrentCell as follows:
Me.EvalItemsDataGridView.C urrentCell = Me.EvalItemsDataGridView(0 , 0)
That works fine.
However, there are times that the user will select a row and then move to another form to do other work on that selected record. Upon returning to Form1 I want the DataGridView row to be set to that previously selected row. I do save the Key to that record when it is initially selected.
For instance:
SavedKey = the selected record ItemID (which is a field in the DataGridControl.) SavedKey is never modified or replaced while the user works the record on another form and then returns to Form1.
Here is the question:
If SavedKey = 0 then
Me.EvalItemsDataGridView.C urrentCell = Me.EvalItemsDataGridView(0 , 0)
Else
How can I locate and highlight the SavedKey record when returning to Form1?
end if
Me.EvalItemsDataGridView.C
That works fine.
However, there are times that the user will select a row and then move to another form to do other work on that selected record. Upon returning to Form1 I want the DataGridView row to be set to that previously selected row. I do save the Key to that record when it is initially selected.
For instance:
SavedKey = the selected record ItemID (which is a field in the DataGridControl.) SavedKey is never modified or replaced while the user works the record on another form and then returns to Form1.
Here is the question:
If SavedKey = 0 then
Me.EvalItemsDataGridView.C
Else
How can I locate and highlight the SavedKey record when returning to Form1?
end if
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
well.. is the form being closed, or just losing focus?
ASKER
The Form1does not close until the app is closed.
fyi.. form_load happens when the form is .. well... loaded. (once).
form_activate happens everytime it gets focus.. I believe even when you minimize and restore.
if the form is still loaded.. I would put your code "Me.EvalItemsDataGridView. CurrentCel l = Me.EvalItemsDataGridView(0 , 0)"
in the load.. when the form loses focus, and comes back.. the control should still be on the same cell/row it was on.
if it's closing.. you should put that code (with stuff like what I typed) in the load.
activate is usually only used for stuff you want to happen often.
form_activate happens everytime it gets focus.. I believe even when you minimize and restore.
if the form is still loaded.. I would put your code "Me.EvalItemsDataGridView.
in the load.. when the form loses focus, and comes back.. the control should still be on the same cell/row it was on.
if it's closing.. you should put that code (with stuff like what I typed) in the load.
activate is usually only used for stuff you want to happen often.
another thing.. since it's still loaded.. if you are not using modal forms.. than it would be possible for your user to go to form1, and change the control.. effectively making the parent and child forms out of sync.
ASKER
Thanks for your help on this.
ASKER