Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Setting Focus in a DataGridView. How can I accomplish this? 1

Status
Not open for further replies.

RotorTorque

Programmer
Joined
Apr 29, 2007
Messages
100
Location
US
Hi all,
I have a VB2005 app in which I use a DataGridView control. One of the columns in my DataGridView is a button column. When the button is clicked a pop-up window is diplayed. When this pop-up window is closed I would like focus to go back to the row from where the button was clicked, but instead focus is set to the first row in the DataGridView. How can I accomplish what this?


Thanks in advance,
RotorTorque :-)
 
I had a user request a similar setup and here is what I came up with. Might be a better solution out there, but this works a treat for me.

Code:
'This gets the index of the first row
'displayed on the screen
Dim FirstDisplayedIndex As Int32 = Me.dgvInventory.Rows.GetFirstRow(DataGridViewElementStates.Displayed)

'This block opens my edit form
Dim frm As New EditInventory
frm.intInventoryId = Me.intCurrentId
frm.ShowDialog()

'This refreshes my datagridview
Me.dgvInventory.Fill(Me.DsSims.vInventoryByWarehouseAndAllocationGroup)

'This is the key to my example...
'It takes the index found in the
'first step and makes the datagridview
'display that row as the first one on the screen
Me.VInventoryByWarehouseAndAllocationGroupDataGridView.FirstDisplayedScrollingRowIndex = FirstDisplayedIndex

=======================================
People think it must be fun to be a super genius, but they don't realize how hard it is to put up with all the idiots in the world. (Calvin from Calvin And Hobbs)

Robert L. Johnson III
CCNA, CCDA, MCSA, CNA, Net+, A+, CHDP
VB/Access Programmer
 
Thanks mstrmage1768,

I will let you know the outcome.

RotorTorque :-)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top