Selecting row in Datagridview
I have a datagridview that gets populatedfrom an XML file when the form loads. One of the XML fields indicates which datagridview row was selected when the application closed. When I load the form and I can find the row and set it to "selected". This works and the row gets highlighted (selected = true) the problem that I'm having is the row selector (little black triangle on the left) always points to the first row until the user clicks the grid. After that the highlighted row and the row selector agree. Is there another property to set the row selector?
Here's the code that I'm using to select the row.
vb Code:
For i = 0 To dsLoads.Tables("Loads").Rows.Count - 1
dv = Me.grdLoads.Item("loaded", i)
If CType(dv.Value, Integer) = 1 Then
row = i
grdLoads.Rows(row).Selected = True
End If
Next
Re: Selecting row in Datagridview
Hi,
Here's a link how to selecting a row in a Datagridview.
http://msdn2.microsoft.com/en-us/lib...ectedrows.aspx
Wkr,
sparrow1
Re: Selecting row in Datagridview
Thanks Sparrow, but that is a link on how to manipulate rows that have been selected by the user. I am programatically selecting the row. As I mentioned in my original post, my code will select the correct row but the DGV row selected indicator ( I don't know what it's reaaly called) does not match the selected row. If I use a message bos to display the contents of the selected row I get what I would expect. My problem is that users thinks that row one is selected (when it's not) because of te little black pointer on the left.
I can always just reduce the size of the row header until the pointer is not visible but I was looking for the "real" answer.
Re: Selecting row in Datagridview
Try setting the CurrentCell property to a cell in that row. That's a stab in the dark but it may work.
Re: Selecting row in Datagridview
Nice Stab. Worked great, thanks.
vb Code:
grdLoads.CurrentCell = grdLoads(0, i)