Solved

DatagridView Selected Row

Posted on 2008-10-08
4
669 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
  • 2
4 Comments
 
LVL 18

Accepted Solution

by:
lludden earned 250 total points
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
Hi JPaulino, yes indeed. You're correct. Thank you very much.
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

If you're writing a .NET application to connect to an Access .mdb database and use pre-existing queries that require parameters, you've come to the right place! Let's say the pre-existing query(qryCust) in Access takes a Date as a parameter and l…
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.
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

762 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

Need Help in Real-Time?

Connect with top rated Experts

7 Experts available now in Live!

Get 1:1 Help Now