DevExpress GridView Row Color

99封情书 提交于 2021-02-11 15:15:57

问题


Anyone here knows how to accomplish this kind of rows using DevExpress GridView on WinForms?


回答1:


I suggest you to go through documentation for the topic: Customizing Appearances of Individual Rows and Cells.

You can do this using various ways:

  1. Customizing Appearances
  2. Using the GridView.CustomDrawCell event

The GridView.RowStyle event can be handled to customize the appearance of individual rows in GridViews. To customize a specific cell's appearance, handle the GridView.RowCellStyle event instead. The GridView.RowStyle event fires before the GridView.RowCellStyle event.

Example:

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;
      }            
   }
}

References:
Changing Row Colours on DevExpress GridView

Hope this help..




回答2:


You click on GridView and then click on Theme, you can choose from this.




回答3:


Here is how you would do in a DataGridView control in forms. Should be similar I assume, it has been a while since I last used DevExpress. But you should go through the DevExpress' documentation, since all of the components are very well documented.

foreach (DataGridViewRow row in dgInformation.Rows)
{
    if (some criteria here == 1234)
    {
        row.DefaultCellStyle.BackColor = Color.Goldenrod;
    }
}


来源:https://stackoverflow.com/questions/38045342/devexpress-gridview-row-color

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!