Solved

DatagridView Selected Row

Posted on 2008-10-08
4
670 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
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

This article explains how to create and use a custom WaterMark textbox class.  The custom WaterMark textbox class allows you to set the WaterMark Background Color and WaterMark text at design time.   IMAGE OF WATERMARKS STEPS Create VB …
This tutorial demonstrates one way to create an application that runs without any Forms but still has a GUI presence via an Icon in the System Tray. The magic lies in Inheriting from the ApplicationContext Class and passing that to Application.Ru…
Along with being a a promotional video for my three-day Annielytics Dashboard Seminor, this Micro Tutorial is an intro to Google Analytics API data.
In this video I am going to show you how to back up and restore Office 365 mailboxes using CodeTwo Backup for Office 365. Learn more about the tool used in this video here: http://www.codetwo.com/backup-for-office-365/ (http://www.codetwo.com/ba…

911 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

23 Experts available now in Live!

Get 1:1 Help Now