views:

1162

answers:

3

Hi,

how can I paint all rows in a datagrid with the value of field "age" = 30 in red?

I work in WinCE.

Thanks for any help!

+1  A: 

The answer hasn't changed since the last time you asked.

ctacke
but in this example it paint all rows in 2 colors, and i need only row that age = 30. (i dont understand the example class)
Gold
A: 

I'd suggest going back to the example ctacke linked to and specifically looking at:

DataGridCustomColumnBase.DrawBackground

There it supports colouring a row in a particular colour for alternative rows. Once you've understood this in its entirity it shouldn't be too hard to paint them whatever colour you want whenever you want.

The example code is so awesome that you could play with the full framework and then port your knowledge (as the guy has made his code cross-compatible with the CF <-> FF) to CF. Re-read and grok that example because it is a very nice one.

Quibblesome
Ilya is nothing if not thorough.
ctacke
+1  A: 

try something like. I set

Datagrid1.Datasource = Datatable1.DefaultView

where Datatable1 is a Datatable that contains a column named "Age"

Sorry, is in VB

Private Sub paintColors()

    Dim vI As Int64 
    DataGrid1.SelectionBackColor = Color.OrangeRed
    Dim vI As Int64 = 0
    For vI = 0 To Datatable1.DefaultView.Count - 1

        If Datatable1.DefaultView.Item(vI)("Age") = 30 Then
            DataGrid1.Select(vI)
        Else
            DataGrid1.UnSelect(vI)
        End If

    Next

End Sub

Marcel