[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 391
  • Last Modified:

Help with selecting Row when click on checkbox using VB.NET

Hi,

I'm adding a checkbox in the first column of my Grid using the code in partA, when I click on the checkbox, How do I also highlight the entire row? and If I uncheck the box, how do I also umhighlight the row?



Part A:

Dim CheckBoxCol As New DataGridViewCheckBoxColumn
        With CheckBoxCol
            .Name = "CheckBoxColumn"
            .HeaderText = "Select"
            .Width = 40
        End With
        Me.C1TrueDBGrid3.Columns.Insert(0, CheckBoxCol)
Thanks,

Victor
0
vcharles
Asked:
vcharles
  • 2
1 Solution
 
John (Yiannis) ToutountzoglouCommented:
Hi Victor....

Try this code ..
 Private Sub DataGridView1_CellValueChanged(sender As System.Object, e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DataGridView1.CellValueChanged
        Try


            If DataGridView1.Columns(e.ColumnIndex).Name = "CheckBoxColumn" Then

                Dim checkCell As DataGridViewCheckBoxCell = _
                    CType(DataGridView1.Rows(e.RowIndex).Cells("CheckBoxColumn"),  _
                    DataGridViewCheckBoxCell)
                If CType(checkCell.Value, [Boolean]) = True Then
                    For i As Integer = 0 To Me.DataGridView1.Columns.Count - 1
                        DataGridView1.Rows(e.RowIndex).Cells(i).Style.BackColor = Color.Red
                        DataGridView1.Rows(e.RowIndex).Cells(i).Style.SelectionBackColor = Color.Red
                    Next
                Else
                    For j As Integer = 0 To Me.DataGridView1.Columns.Count - 1
                        DataGridView1.Rows(e.RowIndex).Cells(j).Style.BackColor = Color.White
                        DataGridView1.Rows(e.RowIndex).Cells(j).Style.SelectionBackColor = Color.White
                    Next
                End If

                DataGridView1.Invalidate()
            End If
        Catch ex As Exception
            MessageBox.Show(ex.Message)
        End Try
    End Sub

    Private Sub DataGridView1_CurrentCellDirtyStateChanged(sender As System.Object, e As System.EventArgs) Handles DataGridView1.CurrentCellDirtyStateChanged
        If DataGridView1.IsCurrentCellDirty Then
            DataGridView1.CommitEdit(DataGridViewDataErrorContexts.Commit)
        End If
    End Sub

Open in new window


Yiannis...
0
 
vcharlesAuthor Commented:
Hi,
I will try it and get back to you.
Thanks.

V,
0
 
vcharlesAuthor Commented:
It works!

Thank You!

Victor
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now