DevExpress Gridview - format rows in C# based on certain condition
Solution 1
Try this for DevExpress Gridview
using DevExpress.XtraGrid.Views.Grid;
private void gridView1_RowStyle(object sender,
DevExpress.XtraGrid.Views.Grid.RowStyleEventArgs e) {
GridView View = sender as GridView;
if(e.RowHandle >= 0) {
string category = View.GetRowCellDisplayText(e.RowHandle, View.Columns["Category"]);
if(category == "Beverages") {
e.Appearance.BackColor = Color.Salmon;
e.Appearance.BackColor2 = Color.SeaShell;
}
}
}
Output
Solution 2
private void grvAssesse_RowCellStyle(object sender, DevExpress.XtraGrid.Views.Grid.RowCellStyleEventArgs e)
{
if (e.RowHandle >= 0)
{
GridView View = sender as GridView;
if (Condition)
{
e.Appearance.ForeColor = Color.Red;
}
}
}
You need to set condition globally, on the basis of that condition grid will execute this event for each row loading.
For More details refer: GridView
aioracle
Updated on June 16, 2022Comments
-
aioracle almost 2 years
I am using DevExpress GridView and binding data via C# code.
My requirement is to change the row color based on the calculation I perform in my code logic.
I want to traverse through all the rows available and if the row cell value matches the condition's result I need to change the color.
I have seen examples and sample source on the web but nothing seems to point me to resolve the issue. Most of them are using XAML code or using DataBinding or during DataBound etc. I am not so comfortable using inotifyvaluechange.
Look forward to your support and suggestions.
-
aioracle over 11 yearsRuchi, I think i forgot to mention. Sorry! I am using the WPF control not the ASPX.
-
Ruchi over 11 yearsI think this article might help you :
-
Ruchi over 11 years