Solved

Help with selecting all rows in a DataGrid

Posted on 2013-10-27
7
234 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
What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

 

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

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

Suggested Solutions

Recently while returning home from work my wife (another .NET developer) was murmuring something. On further poking she said that she has been assigned a task where she has to serialize and deserialize objects and she is afraid of serialization. Wha…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

708 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now