![](/img/trans.png)
[英]move Rows up and down or change row color if the row cell value are the same gridview devexpress winforms c#?
[英]Change the color of a cell in gridview devexpress not row
我有一個顯示大量數據的grid view devexpress c#
,我需要根據數據值設置單元格的顏色,如下所示:
private void gridView_RowStyle_1(object sender, RowStyleEventArgs e)
{
if (e.RowHandle >= 0)
{
// Some condition
if (gridView.GetRowCellValue(e.RowHandle, gridView.Columns["Id"]).ToString() == "2")
{
e.Appearance.BackColor = Color.Green;
}
}
}
但是此功能會更改整個行的顏色而不是單元格。我如何設置單元格的顏色?
使用GridView.RowCellStyle事件,如下所示:
void gridView1_RowCellStyle( object sender, RowCellStyleEventArgs e)
{
GridView currentView = sender as GridView;
if (e.Column.FieldName == "Customer" )
{
bool value = Convert.ToBoolean(currentView.GetRowCellValue(e.RowHandle, "Flag_Customer" ));
if (value)
e.Appearance.BackColor = Color.Red;
}
if (e.Column.FieldName == "Vendor" )
{
bool value = Convert.ToBoolean(currentView.GetRowCellValue(e.RowHandle, "Flat_Vendor" ));
if (value)
e.Appearance.BackColor = Color.Red;
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.