RIAS
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
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
End If
ASKER
Is there any other way apart from looping thr the rows in datagrdiview
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.
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.
Please refer to this URL - https://msdn.microsoft.com/en-us/library/system.windows.forms.datagridview.selectall(v=vs.110).aspx
ASKER
Tried SelectAll method but,it does not put check or true value in the checkbox column.
ASKER
Basically want to avoid looping through all the rows as its taking a lot of time.
>>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?
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?
ASKER
Andy,
I have rows like 50K.
I have rows like 50K.
And it works with reasonable performance?
Do you know about virtual mode ?
Do you know about virtual mode ?
ASKER
It works but,just need a better way.
No not tried virtual mode.
No not tried virtual mode.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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
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
The requirement is to keep it unselected on load then there is a button for selectAll.
Selectall will select all rows on the grid
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Cheers!
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.