Hi all,
I have a datagrid displaying trivial information, however, I need to color the row of the DataGrid dependant on the value of one column.
I've figured out how to change the color of the column, but not the whole row.
Any help appreicated.
ie. if the column lastname contains 'jones' then make the entire row red. if it contains 'smith' make the entire row green.
I need to do this for all rows, NOT just the selected row.
Thanks.
J.

Format a DataGrid row based on value of column
vodka
I need to do exactly the same thing :)
Geoff Henry
Try this url http://www.syncfusion.com/FAQ/WinForms/FAQ_c44c.asp#q745q, it has sample on how to color the whole row.
Thanks,
Lan
Lgee212
I have just found this code sample after much searching! I want to change the color of a row depending on the value in column 6.
I have copied the code exactly as it is above except with my own expresion but i am given a invalidCastException.
This is really bugging me now so any help will be greatly appreciatted,
David
byx45
I needed to set the row color based on the value of two columns in the grid. I could do this by referencing the Me.DataGridTableStyle.DataGrid.DataSource() property which holds a reference to the DataTable that conatains all the data, then I selected the DataRow using the Rows collection and the RowNum value and check the value of the two columns. The code I used is shown below.
Protected Overloads Overrides Sub Paint(ByVal g As Graphics, ByVal bounds As Rectangle, ByVal source As CurrencyManager, ByVal rowNum As Integer, ByVal backBrush As Brush, ByVal foreBrush As Brush, ByVal alignToRight As Boolean)
Dim dtPurchases As DataTable
Dim PurchaseDataRow As DataRow
' the idea is to conditionally set the foreBrush and/or backbrush
' depending upon some crireria on the cell value
' Here, we color anything when columns Purchase amount and Confirm amount do not equal each other
Try
Dim o As Boolean
dtPurchases = Me.DataGridTableStyle.DataGrid.DataSource()
PurchaseDataRow = dtPurchases.Rows(rowNum)
o = (NothingToBlank(PurchaseDataRow("Confirm Amount").ToString) = PurchaseDataRow("Purchase Amount").ToString)
If Not o Then
backBrush = New LinearGradientBrush(bounds, Color.FromArgb(255, 0, 0), Color.FromArgb(128, 20, 20), LinearGradientMode.Vertical)
foreBrush = New SolidBrush(Color.White)
End If
Catch ex As Exception
' empty catch
Finally
' make sure the base class gets called to do the drawing with
' the possibly changed brushes
MyBase.Paint(g, bounds, source, rowNum, backBrush, foreBrush, alignToRight)
End Try
End Sub
SolarScott
Cheers for the reply. I've seen this sample, the down side is that it uses the value of the currentCell to control the color. ie. if thisCell.value > F ....
What I need to do is find a way of saying if the value of cell[0] >'F' then color = red etc...
ie. base the color on a criteria other than the value of the currentCell.
Thanks.
Julian.
kimberst
Can u pl keep the entire code.
I did the same thing but only 1 column is getting colored i want entire row to be colored.