Avatar of RIAS
RIAS
Flag for United Kingdom of Great Britain and Northern Ireland asked on

Select all rows in datagridview

Hello,

Need to set boolean value to true all the rows in datagridview.
Tried SelectAll method but,it does not put check or true value in the checkbox column.

The selection clolumn is added in datagridview as follows:

 If dg.Name <> "DgHelpUsers" Then
                .Columns.Add("Sel", GetType(Object))
                .Columns("Sel").SetOrdinal(0)
            End If
.NET ProgrammingVisual Basic.NET

Avatar of undefined
Last Comment
RIAS

8/22/2022 - Mon
AndyAinscow

Select will select things - it is not the same as setting a value in a check box.  They are two different things altogether.

I think you will have to loop through all the rows in the datagridview and explicitly set the value of the cheeckbox to whatever you want.
RIAS

ASKER
Is there any other way apart from looping thr the rows in datagrdiview
AndyAinscow

If the source is a database you could run an update query and then repopulate the grid.

Built in functionality will do things with the gridview.  You want to change the contents - which is your data and a bit away from the base functionality the gridview needs.
All of life is about relationships, and EE has made a viirtual community a real community. It lifts everyone's boat
William Peck
Pallavi Godse

RIAS

ASKER
Tried SelectAll method but,it does not put check or true value in the checkbox column.
RIAS

ASKER
Basically want to avoid looping through all the rows as its taking a lot of time.
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
AndyAinscow

>>Basically want to avoid looping through all the rows as its taking a lot of time.
Bear in mind:  Sometimes what one wants one can't have.

What sort of time is it taking?  How many rows?  Can you modify the underlying data then refresh the GUI?
RIAS

ASKER
Andy,

I have rows like 50K.
AndyAinscow

And it works with reasonable performance?

Do you know about virtual mode ?
This is the best money I have ever spent. I cannot not tell you how many times these folks have saved my bacon. I learn so much from the contributors.
rwheeler23
RIAS

ASKER
It works but,just need a better way.
No not tried virtual mode.
ASKER CERTIFIED SOLUTION
Scott McDaniel (EE MVE )

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
RIAS

ASKER
I add column like this :
  Public Sub BindDatagridview(ByVal dt As DataTable, ByVal dg As DataGridView)
        Dim dv As DataView
        With dt
            'Outstanding  check List_MouseDown
            Dim SQL As String = String.Empty
            'Initialize the image column.
            If dg.Name <> "DgHelpUsers" Then
                .Columns.Add("Sel", GetType(Object))
                .Columns("Sel").SetOrdinal(0)
            End If
            If dt.Rows.Count <> 0 Then
                dg.DataSource = dt
                dg.Rows(0).Selected = False
                dg.ClearSelection()
                For inti = 0 To dg.DataSource.columns.count - 1
                    dg.Columns(inti).SortMode = DataGridViewColumnSortMode.Programmatic
                Next
                If dg.Name <> "DgHelpUsers" Then
                    With dg.Columns("Sel")
                        .ToolTipText = "Selection"
                        .HeaderText = ""
                        .DefaultCellStyle.ForeColor = Color.Transparent
                        .Width = 15
                    End With

                End If
            Else
                'The datatable is empty so load only the columns
                dv = New DataView(dt)
                'add code for sorting as original defaultview
                dg.DataSource = dv
            End If
        End With
    End Sub

Open in new window

RIAS

ASKER
Scott,
The requirement is to keep it unselected on load then there is a button for selectAll.
Selectall will select all rows on the grid
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
SOLUTION
AndyAinscow

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
RIAS

ASKER
Cheers!