[Webinar] Streamline your web hosting managementRegister Today

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 679
  • Last Modified:

DatagridView Selected Row

HI, I'm using VB 2005, WinForms. I have a DataGridView in which I highlight the selected row as follows:

myDGV.RowsDefaultCellStyle.SelectionBackColor = Color.LightSeaGreen

How do I programatically move the selected row from one row to the next? Lets say my selected row is row of index 10. How do I move the selection forward to row 13 or back to row 7?

Thanks,
Fulano
0
Mr_Fulano
Asked:
Mr_Fulano
  • 2
2 Solutions
 
lluddenCommented:
datagrid views allow for multiple rows to be selected (if select multi is true)
To set any specific row as selected:

myDGV.Rows(index).selected = true
0
 
Mr_FulanoAuthor Commented:
Hi lludden, yes indeed you suggestion is correct. However, it leads me to a followup question, which I now see happening. If the selected row is outside the viewable area (way down at the bottom of the list) in the DGV, how do you make the DGV scroll up to the top of the viewable area -- or at least within the viewable area using your code?

Thanks,
Fulano
0
 
Jorge PaulinoIT Pro/DeveloperCommented:
Hi Fulano,
You can do this
Dim rowIndex As Integer = 1
Me.DataGridView1.CurrentCell = Me.DataGridView1.Rows(rowIndex ).Cells(0)
Me.DataGridView1.FirstDisplayedScrollingRowIndex = rowIndex
0
 
Mr_FulanoAuthor Commented:
Hi JPaulino, yes indeed. You're correct. Thank you very much.
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now