Solved

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

Posted on 2013-10-29
3
383 Views
Last Modified: 2013-10-30
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
Comment
Question by:vcharles
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 18

Accepted Solution

by:
John (Yiannis) Toutountzoglou earned 500 total points
ID: 39610425
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
 

Author Comment

by:vcharles
ID: 39610807
Hi,
I will try it and get back to you.
Thanks.

V,
0
 

Author Comment

by:vcharles
ID: 39610903
It works!

Thank You!

Victor
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

It’s quite interesting for me as I worked with Excel using vb.net for some time. Here are some topics which I know want to share with others whom this might help. First of all if you are working with Excel then you need to Download the Following …
A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

749 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question