Solved

Help with selecting all rows in a DataGrid

Posted on 2013-10-27
7
237 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
  • 4
  • 3
7 Comments
 
LVL 62

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 62

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
Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

 

Author Comment

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

Expert Comment

by:Fernando Soto
ID: 39606496
OK
0
 

Author Closing Comment

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

Expert Comment

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

Featured Post

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Not seen Link button 5 39
VB.NET 2008 Populate DataModel with DataTable 44 28
Disable extension 8 38
Modal Popup Extender control 1 20
Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

773 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