?
Solved

How to color a datagridview row if checkbox is unchecked

Posted on 2007-10-10
3
Medium Priority
?
653 Views
Last Modified: 2013-11-26
In a bound datagridview:
I need sample code to color a datagridview row if checkbox is unchecked.
0
Comment
Question by:dave_sky
  • 2
3 Comments
 
LVL 96

Accepted Solution

by:
Bob Learned earned 2000 total points
ID: 20058996
Dave,

Here is an cobbled together example, using VirtualMode:

    Private flags(4) As Boolean

    Private Sub DataGridView1_CellValueNeeded(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewCellValueEventArgs) Handles DataGridView1.CellValueNeeded
        If e.ColumnIndex = Me.Column1.Index Then
            e.Value = "5"
        Else
            e.Value = flags(e.RowIndex)
        End If
    End Sub

    Private Sub DataGridView1_CellMouseUp(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewCellMouseEventArgs) Handles DataGridView1.CellMouseUp
        If e.ColumnIndex = Me.Column2.Index Then
            flags(e.RowIndex) = Not flags(e.RowIndex)
            Dim value As Boolean = flags(e.RowIndex)
            If value Then
                Me.DataGridView1.Rows(e.RowIndex).DefaultCellStyle.BackColor = Color.Red
            Else
                Me.DataGridView1.Rows(e.RowIndex).DefaultCellStyle.BackColor = Me.DataGridView1.DefaultCellStyle.BackColor
            End If
        End If
    End Sub

Bob
0
 

Author Comment

by:dave_sky
ID: 20061625
Bob,
Is there any way to make this work so the color stays on a refresh?

Dave
0
 

Author Comment

by:dave_sky
ID: 20075179
Bob.
Thanks, the question was answered as written.

0

Featured Post

Nothing ever in the clear!

This technical paper will help you implement VMware’s VM encryption as well as implement Veeam encryption which together will achieve the nothing ever in the clear goal. If a bad guy steals VMs, backups or traffic they get nothing.

Question has a verified solution.

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

Many of us here at EE write code. Many of us write exceptional code; just as many of us write exception-prone code. As we all should know, exceptions are a mechanism for handling errors which are typically out of our control. From database errors, t…
Simulator games are perfect for generating sample realistic data streams, especially for learning data analysis. It is even useful for demoing offerings such as Azure stream analytics, PowerBI etc.
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …
When cloud platforms entered the scene, users and companies jumped on board to take advantage of the many benefits, like the ability to work and connect with company information from various locations. What many didn't foresee was the increased risk…
Suggested Courses

864 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