Solved

Help with selecting all rows in a DataGrid

Posted on 2013-10-27
7
241 Views
Last Modified: 2013-10-29
Hi,

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

Thanks,

Victor
0
Comment
Question by:vcharles
[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
  • 4
  • 3
7 Comments
 
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?
0
 

Author Comment

by:vcharles
ID: 39604802
Hi,

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

Thanks.
0
 
LVL 63

Accepted Solution

by:
Fernando Soto earned 500 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
Next

Open in new window

0
MS Dynamics Made Instantly Simpler

Make Your Microsoft Dynamics Investment Count  & Drastically Decrease Training Time by Providing Intuitive Step-By-Step WalkThru Tutorials.

 

Author Comment

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

Expert Comment

by:Fernando Soto
ID: 39606496
OK
0
 

Author Closing Comment

by:vcharles
ID: 39607793
Thank You.
0
 
LVL 63

Expert Comment

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

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
VB.Net creating Contact in Outlook 1 60
Groupbox Control ? 2 30
Regarding swagger API 1 38
VB.net Excel VSTO Add-in version compatability 2 19
In my previous article (http://www.experts-exchange.com/Programming/Languages/.NET/.NET_Framework_3.x/A_4362-Serialization-in-NET-1.html) we saw the basics of serialization and how types/objects can be serialized to Binary format. In this blog we wi…
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…
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 …

696 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