Solved

DatagridView Selected Row

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

On Demand Webinar: Networking for the Cloud Era

Ready to improve network connectivity? Watch this webinar to learn how SD-WANs and a one-click instant connect tool can boost provisions, deployment, and management of your cloud connection.

Question has a verified solution.

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

Well, all of us have seen the multiple EXCEL.EXE's in task manager that won't die even if you call the .close, .dispose methods. Try this method to kill any excels in memory. You can copy the kill function to create a check function and replace the …
The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
There are cases when e.g. an IT administrator wants to have full access and view into selected mailboxes on Exchange server, directly from his own email account in Outlook or Outlook Web Access. This proves useful when for example administrator want…
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…

623 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