问题
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:
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
回答2:
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.
来源:https://stackoverflow.com/questions/504558/paint-datagrid-row-in-color-in-wince