Solved

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

Posted on 2013-10-29
3
385 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

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

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

In my previous two articles we discussed Binary Serialization (http://www.experts-exchange.com/A_4362.html) and XML Serialization (http://www.experts-exchange.com/A_4425.html). In this article we will try to know more about SOAP (Simple Object Acces…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…

726 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