check all checkbox in datagrid window form
-
Hi, I have a datagrid and a checkbox template column is bounded to it on the 1st column. I want to check/uncheck all the checkboxes at once when user click the check/uncheck checkbox in the header template. I got the all the sample codes in Javascript and asp. But not for vb.net window application. Can anyone guide me the codes on window application? It would be grateful if you already have the reference and send it to me. Thanks a lot for ur help.
-
Hi, I have a datagrid and a checkbox template column is bounded to it on the 1st column. I want to check/uncheck all the checkboxes at once when user click the check/uncheck checkbox in the header template. I got the all the sample codes in Javascript and asp. But not for vb.net window application. Can anyone guide me the codes on window application? It would be grateful if you already have the reference and send it to me. Thanks a lot for ur help.
I found this article here on Code Project. http://www.codeproject.com/KB/grid/DataGridView_winforms.aspx[^] I converted the below method for you, from C# to VB.NET. Just wire up this event handler and set the column index to match your data grid layout. The below code assumes that the CheckBox column is the first column, so if your is not, you'll need to make a few changes: Just change the two following lines of code and replace the "0" with the correct column index.
If e.ColumnIndex = **0** Then
dataGridView1.Rows(i).Cells(**0**).Value = dgvColumnHeader.CheckAll
Private Sub dataGridView1_ColumnHeaderMouseClick(ByVal sender As Object, ByVal e As DataGridViewCellMouseEventArgs)
If e.ColumnIndex = 0 Then
For i As Integer = 0 To dataGridView1.Rows.Count - 1
dataGridView1.Rows(i).Cells(0).Value = dgvColumnHeader.CheckAll
Next
End If
End SubCheers, Karl
» CodeProject 2008 MVP My Blog | Mole's Home Page | How To Create Screen Capture Videos For Your ArticlesJust a grain of sand on the worlds beaches.
-
I found this article here on Code Project. http://www.codeproject.com/KB/grid/DataGridView_winforms.aspx[^] I converted the below method for you, from C# to VB.NET. Just wire up this event handler and set the column index to match your data grid layout. The below code assumes that the CheckBox column is the first column, so if your is not, you'll need to make a few changes: Just change the two following lines of code and replace the "0" with the correct column index.
If e.ColumnIndex = **0** Then
dataGridView1.Rows(i).Cells(**0**).Value = dgvColumnHeader.CheckAll
Private Sub dataGridView1_ColumnHeaderMouseClick(ByVal sender As Object, ByVal e As DataGridViewCellMouseEventArgs)
If e.ColumnIndex = 0 Then
For i As Integer = 0 To dataGridView1.Rows.Count - 1
dataGridView1.Rows(i).Cells(0).Value = dgvColumnHeader.CheckAll
Next
End If
End SubCheers, Karl
» CodeProject 2008 MVP My Blog | Mole's Home Page | How To Create Screen Capture Videos For Your ArticlesJust a grain of sand on the worlds beaches.
Hi Karl, Thanks for the sharing. But in window form it doesn't have DataGridViewCellMouseEventArgs. What shall I change it to? Appreciate your help again. Thanks. cheers,eunice
-
I found this article here on Code Project. http://www.codeproject.com/KB/grid/DataGridView_winforms.aspx[^] I converted the below method for you, from C# to VB.NET. Just wire up this event handler and set the column index to match your data grid layout. The below code assumes that the CheckBox column is the first column, so if your is not, you'll need to make a few changes: Just change the two following lines of code and replace the "0" with the correct column index.
If e.ColumnIndex = **0** Then
dataGridView1.Rows(i).Cells(**0**).Value = dgvColumnHeader.CheckAll
Private Sub dataGridView1_ColumnHeaderMouseClick(ByVal sender As Object, ByVal e As DataGridViewCellMouseEventArgs)
If e.ColumnIndex = 0 Then
For i As Integer = 0 To dataGridView1.Rows.Count - 1
dataGridView1.Rows(i).Cells(0).Value = dgvColumnHeader.CheckAll
Next
End If
End SubCheers, Karl
» CodeProject 2008 MVP My Blog | Mole's Home Page | How To Create Screen Capture Videos For Your ArticlesJust a grain of sand on the worlds beaches.
My bad. It's been a very long day. It's the same event,
ColumnHeaderMouseClick
just different signature.Private Sub myDataGrid_ColumnHeaderMouseClick(ByVal sender As Object, ByVal e As _
System.Windows.Forms.DataGridViewCellMouseEventArgs) Handles myDataGrid.ColumnHeaderMouseClickCheers, Karl
» CodeProject 2008 MVP My Blog | Mole's Home Page | How To Create Screen Capture Videos For Your ArticlesJust a grain of sand on the worlds beaches.