VB 2008  - How to Select rows in a DataGridView

Posted on 2009-07-09
Last Modified: 2012-05-07
How do I select a row, or several rows (if multi-select) in a DataGridView?
Question by:ljcor
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
  • 3
  • 3
LVL 15

Accepted Solution

JackOfPH earned 500 total points
ID: 24811891
What do you mean? Select? Highlight multiple rows?

Try this, The following code will select the first and third row in the datagridview

Datagridview1.Rows(0).Selected = True  
Datagridview1.Rows(2).Selected = True

Author Closing Comment

ID: 31601493
Yes, that is exactly what I wanted to do.   Thanks again.  Today I remember where you live!!  Italy?
Just kidding.  I do remember.
LVL 15

Expert Comment

ID: 24811915
Creating Instructional Tutorials  

For Any Use & On Any Platform

Contextual Guidance at the moment of need helps your employees/users adopt software o& achieve even the most complex tasks instantly. Boost knowledge retention, software adoption & employee engagement with easy solution.


Author Comment

ID: 24811960
Perhaps you can add to this answer just so I know:  How can I select ALL rows in the grid?

For each row in MyDataGridView  (or something like that?)


LVL 15

Expert Comment

ID: 24819468
Here: Sorry for the long response, I went home early yesterday... here is the code you want to do...

For each row as DatagridviewRow in MyDatagridview.rows
row.Selected = true

Open in new window


Author Comment

ID: 24820119
I can always wait for a right answer.  Thanks Jack.

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

Suggested Solutions

Title # Comments Views Activity
Consume a webservice via VB in Visual Studio 2015 3 45 background worker crossthread 11 44
Adding Rows to Grid 4 33
ErrorKind in crystal reprot VB.Net 1 17
1.0 - Introduction Converting Visual Basic 6.0 (VB6) to Visual Basic 2008+ (VB.NET). If ever there was a subject full of murkiness and bad decisions, it is this one!   The first problem seems to be that people considering this task of converting…
Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below.…
Attackers love to prey on accounts that have privileges. Reducing privileged accounts and protecting privileged accounts therefore is paramount. Users, groups, and service accounts need to be protected to help protect the entire Active Directory …

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