Help with selecting all rows in a DataGrid

Posted on 2013-10-27
Medium Priority
Last Modified: 2013-10-29

My DataGrid contains two columns a checkbox column from code below and a country column. How do I select all the rows including checkboxes from a button click event using VB.NET?

Private Sub CheckControl()
        Dim CheckBoxCol As New DataGridViewCheckBoxColumn
        With CheckBoxCol
            .Name = "CheckBoxColumn"
            .HeaderText = "Select"
            .Width = 40
        End With
        Me.C1TrueDBGrid3.Columns.Insert(0, CheckBoxCol)
    End Sub


Question by:vcharles
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
  • 4
  • 3
LVL 63

Expert Comment

by:Fernando Soto
ID: 39604617
Hi Victor;

When you say, "How do I select all the rows including checkboxes from a button click event using VB.NET?", do you mean that all the row become a member of the Selected collection of the DataGridView or that all the check boxes have a check placed in them?

Author Comment

ID: 39604802

I would like all the check boxes to  have a check placed in them and change their back color to blue.

LVL 63

Accepted Solution

Fernando Soto earned 2000 total points
ID: 39605891
Hi Victor;

The following code snippet will select all check boxes in the Selected column and mark each line as selected which turns the line blue.

For Each c As DataGridViewRow In C1TrueDBGrid3.Rows
    If c.Cells("Country").Value <> String.Empty Then
        c.Cells("Select").Value = True
        c.Selected = True
    End If

Open in new window

RHCE - Red Hat OpenStack Prep Course

This course will provide in-depth training so that students who currently hold the EX200 & EX210 certifications can sit for the EX310 exam. Students will learn how to deploy & manage a full Red Hat environment with Ceph block storage, & integrate Ceph into other OpenStack service


Author Comment

ID: 39606479
Thank You, will try it and get back to you.
LVL 63

Expert Comment

by:Fernando Soto
ID: 39606496

Author Closing Comment

ID: 39607793
Thank You.
LVL 63

Expert Comment

by:Fernando Soto
ID: 39609401
Not a problem Victor, glad to help.

Featured Post

Understanding Linux Permissions

Linux for beginners: How to view the permissions associated with files and directories and also how you can change them.

Question has a verified solution.

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

Many of us here at EE write code. Many of us write exceptional code; just as many of us write exception-prone code. As we all should know, exceptions are a mechanism for handling errors which are typically out of our control. From database errors, t…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…
Suggested Courses

765 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