|
Hi all,
Iam displaying the data in the datagidview and wanted to select all the data using the checked box. I can only select one by one but not the select all.
Hope that anyone could help.
Thanks | | LiL_Is Wednesday, November 18, 2009 7:31 AM | - Marked As Answer byMartin Xie - MSFTMSFT, ModeratorTuesday, November 24, 2009 8:37 AM
- Unmarked As Answer byLiL_Is Wednesday, November 25, 2009 7:10 AM
- Marked As Answer byLiL_Is Monday, November 30, 2009 5:00 AM
-
| | A.m.a.L - aditi.com - Think Product Wednesday, November 18, 2009 7:43 AM | Hi all,
Iam displaying the data in the datagidview and wanted to select all the data using the checked box. I can only select one by one but not the select all.
Hope that anyone could help.
Thanks
try it If Checkbox1.Checked then
If Button1.Focus Then
Me.DataGridView1.MultiSelect = True
Me.DataGridView1.SelectAll()
end if
Don't judge me, just Upgrade me. Thanks! - Marked As Answer byLiL_Is Monday, November 30, 2009 5:00 AM
-
| | Malange Friday, November 27, 2009 8:25 PM | Do you mean you want to put a checkbox in column header and want to select gridview using checkbox column? An example below adds a checkbox in column header(in middle widthwise) and selects rows based on its checked value. I am adding checkbox to datagridview's 3rd column headerin form's load event
Private Function GetLocation(ByVal ColIndex As Integer, ByVal cb As CheckBox) As Point
Dim cntrlLoc = DataGridView1.GetCellDisplayRectangle(ColIndex, -1, True).Location
Return New Point(cntrlLoc.X + (DataGridView1.Columns(ColIndex).Width / 2 - cb.Width / 2), cntrlLoc.Y + 4)
End Function
Private Sub DataGridView1_ColumnWidthChanged(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewColumnEventArgs) Handles DataGridView1.ColumnWidthChanged
Dim cb As CheckBox = CType(DataGridView1.Controls("cbSelectAll"), CheckBox)
cb.Location = GetLocation(2, cb) '2 is index of third column
End Sub
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim ColInd = 2 ' adding checkbox to third column)
Dim cb As New CheckBox With {.Name = "cbSelectAll", .Size = New Size(14, 14)}
cb.Location = GetLocation(ColInd, cb)
DataGridView1.Controls.Add(cb)
AddHandler cb.CheckedChanged, AddressOf CB_CheckChanged
End Sub
Private Sub CB_CheckChanged(ByVal s As Object, ByVal e As System.EventArgs)
Dim ColInd = 2 ' changing checked value for third column
For Each dr As DataGridViewRow In DataGridView1.Rows
dr.Cells(ColInd).Value = CType(s, CheckBox).Checked
Next
End Sub
<br/>
- Marked As Answer byLiL_Is Monday, November 30, 2009 5:00 AM
-
| | Arjun Paudel Saturday, November 28, 2009 7:46 AM | - Marked As Answer byMartin Xie - MSFTMSFT, ModeratorTuesday, November 24, 2009 8:37 AM
- Unmarked As Answer byLiL_Is Wednesday, November 25, 2009 7:10 AM
- Marked As Answer byLiL_Is Monday, November 30, 2009 5:00 AM
-
| | A.m.a.L - aditi.com - Think Product Wednesday, November 18, 2009 7:43 AM | Hi all,
Iam displaying the data in the datagidview and wanted to select all the data using the checked box. I can only select one by one but not the select all.
Hope that anyone could help.
Thanks
try it If Checkbox1.Checked then
If Button1.Focus Then
Me.DataGridView1.MultiSelect = True
Me.DataGridView1.SelectAll()
end if
Don't judge me, just Upgrade me. Thanks! - Marked As Answer byLiL_Is Monday, November 30, 2009 5:00 AM
-
| | Malange Friday, November 27, 2009 8:25 PM | Do you mean you want to put a checkbox in column header and want to select gridview using checkbox column? An example below adds a checkbox in column header(in middle widthwise) and selects rows based on its checked value. I am adding checkbox to datagridview's 3rd column headerin form's load event
Private Function GetLocation(ByVal ColIndex As Integer, ByVal cb As CheckBox) As Point
Dim cntrlLoc = DataGridView1.GetCellDisplayRectangle(ColIndex, -1, True).Location
Return New Point(cntrlLoc.X + (DataGridView1.Columns(ColIndex).Width / 2 - cb.Width / 2), cntrlLoc.Y + 4)
End Function
Private Sub DataGridView1_ColumnWidthChanged(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewColumnEventArgs) Handles DataGridView1.ColumnWidthChanged
Dim cb As CheckBox = CType(DataGridView1.Controls("cbSelectAll"), CheckBox)
cb.Location = GetLocation(2, cb) '2 is index of third column
End Sub
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim ColInd = 2 ' adding checkbox to third column)
Dim cb As New CheckBox With {.Name = "cbSelectAll", .Size = New Size(14, 14)}
cb.Location = GetLocation(ColInd, cb)
DataGridView1.Controls.Add(cb)
AddHandler cb.CheckedChanged, AddressOf CB_CheckChanged
End Sub
Private Sub CB_CheckChanged(ByVal s As Object, ByVal e As System.EventArgs)
Dim ColInd = 2 ' changing checked value for third column
For Each dr As DataGridViewRow In DataGridView1.Rows
dr.Cells(ColInd).Value = CType(s, CheckBox).Checked
Next
End Sub
<br/>
- Marked As Answer byLiL_Is Monday, November 30, 2009 5:00 AM
-
| | Arjun Paudel Saturday, November 28, 2009 7:46 AM |
|