Combine grouping and only 1 checkbox checked in datagridview problem

  • Thread starter Thread starter KeesBlunder
  • Start date Start date
K

KeesBlunder

Guest
I have 2 code's that works

Only 1 checkbox checked in a datagridview

Private Sub DataGridView1_CellContentClick(sender As Object, e As DataGridViewCellEventArgs) Handles DataGridView1.CellContentClick

If e.ColumnIndex = 0 AndAlso e.RowIndex >= 0 Then
For Each row As DataGridViewRow In DataGridView1.Rows
row.Cells(e.ColumnIndex).Value = False
Next
End If
Dim senderGrid As DataGridView = sender
Dim data = senderGrid.Rows(e.RowIndex).DataBoundItem
If senderGrid.Columns(e.ColumnIndex).GetType() Is GetType(DataGridViewCheckBoxColumn) And e.RowIndex >= 0 Then

'''' do stuf
End If
End Sub

And grouping ( by making text white)

Private Sub DataGridView1_CellFormatting(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellFormattingEventArgs) Handles DataGridView1.CellFormatting
Try
If e.RowIndex > 0 And e.ColumnIndex = 0 Then
If DataGridView1.Item(0, e.RowIndex - 1).Value = e.Value Then
e.Value = ""
ElseIf e.RowIndex < DataGridView1.Rows.Count - 1 Then
DataGridView1.Rows(e.RowIndex).DefaultCellStyle.BackColor = Color.White
End If
End If
Catch ex As Exception

End Try
End Sub


And in Formload

Dim chk As DataGridViewCheckBoxColumn = New DataGridViewCheckBoxColumn()
DataGridView1.Columns.Add(chk)
chk.HeaderText = "Bewerken"
chk.Name = "chk"
DataGridView1.Columns("chk").DisplayIndex = 3




Both work , but not at the same time.

I can show the grouping and checkboxes oke i think it works, but you can select all checkboxes at the same time if you want.

I want to select only 1

so the first code is not working any more , i was trying to combine both but don't know how.

Continue reading...
 
Back
Top