Solved

DatagridView Selected Row

Posted on 2008-10-08
4
672 Views
Last Modified: 2012-05-05
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
Comment
Question by:Mr_Fulano
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 18

Accepted Solution

by:
lludden earned 250 total points
ID: 22674820
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
 

Author Comment

by:Mr_Fulano
ID: 22675442
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
 
LVL 48

Assisted Solution

by:jpaulino
jpaulino earned 250 total points
ID: 22676331
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
 

Author Comment

by:Mr_Fulano
ID: 22682931
Hi JPaulino, yes indeed. You're correct. Thank you very much.
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

751 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question