-1

I have a datagrid which contains a boolean field. When I test the program and click a row's checkbox, it can't change back color of the row immediately, as my code has an event "CellEndEdit", I have to leave the cell to change the color. I tried some other events however couldn't make them work.

How can I change row's back color when the checkbox on datagrid is clicked?

EDIT: This is a Windows Forms application (not WPF) and I'm using Microsoft Visual Studio Express 2013 for Windows Desktop. By the way, it isn't a datagrid, it's a datagridview which is populated from an mdb database.

nikel
  • 653
  • 4
  • 13
  • 24
  • 1
    See my answer here.. http://stackoverflow.com/questions/21842662/how-to-do-textchanged-event-in-datagridview/21842782#21842782 – Trevor Mar 23 '15 at 02:45
  • 1
    wow! thanks a lot. +1 to this answer and the link. – nikel Mar 23 '15 at 12:19

1 Answers1

0

It should look something like this

If CheckBox1.Checked = True Then
     CheckBox1.BackColor = Color.FromArgb(255,255,255)
End If

You could also do something like this.

Private Sub CheckBox1_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CheckBox1.CheckedChanged
    If CType(sender, CheckBox).Checked Then
        CheckBox1.BackColor = Color.FromArgb(255,255,255)
    Else
        CheckBox1.BackColor = Color.FromArgb(0, 0, 0)
    End If
End Sub

UPDATE AFTER KNOWING IT IS A DATAGRID Have you tried something like this?

<DataGridTextColumn Binding="{Binding Name}">
    <DataGridTextColumn.ElementStyle>
        <Style TargetType="{x:Type TextBlock}">
            <Style.Triggers>
                <Trigger Property="checkbox" Value="True">
                    <Setter Property="Background" Value="LightGreen"/>
                </Trigger>
            </Style.Triggers>
        </Style>
    </DataGridTextColumn.ElementStyle>
</DataGridTextColumn>

Seen here Change DataGrid cell colour based on values

Community
  • 1
  • 1
Joe Packer
  • 525
  • 3
  • 15