Solved

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

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

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

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 …
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.
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…

773 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