Home > Net >  Dev GridView how to set a background color?
Dev GridView how to set a background color?

Time:09-27

Good teachers, I use the DEV EXPRESS, how to set up the GridView one row background color?

As shown above, I think the selected lines, according to the color logo old material and new material
I try to write the next, there is no effect, somehow
 
The Load set some properties in
GridView1. OptionsSelection. EnableAppearanceFocusedCell=false;
GridView1. Appearance. SelectedRow. Options. UseBackColor=true;
GridView1. Appearance. SelectedRow. Options. UseBorderColor=true;
GridView1. Appearance. Preview. The Options. UseBackColor=true;
GridView1. Appearance. Preview. The Options. UseBorderColor=true;


Private void toolStripMenuItem_OldMaterial_Click (object sender, EventArgs e)
{
If (gridView1 FocusedRowHandle & lt; 0)
{
return;
}

if (null !=gridView1. Appearance. Preview)
{
GridView1. Appearance. Preview. BackColor=gridView1. Appearance. Row. BackColor;
}

GridView1. Appearance. SelectedRow. BackColor=Color. Red;

}

Private void ToolStripMenuItem_NewMaterial_Click (object sender, EventArgs e)
{
If (gridView1 FocusedRowHandle & lt; 0)
{
return;
}

if (null !=gridView1. Appearance. Preview)
{
GridView1. Appearance. Preview. BackColor=gridView1. Appearance. Row. BackColor;
}

GridView1. Appearance. SelectedRow. BackColor=Color. Green;
}

CodePudding user response:

https://blog.csdn.net/qq_17486399/article/details/50467852
See if you need

CodePudding user response:

Done
 
Private void toolStripMenuItem_OldMaterial_Click (object sender, EventArgs e)
{
If (gridView1 FocusedRowHandle & lt; 0)
{
return;
}

OldPrevMaterialIndex=oldMaterialIndex;
OldMaterialIndex=gridView1. FocusedRowHandle;
GridView1. RefreshRow (oldPrevMaterialIndex);
GridView1. RefreshRow (oldMaterialIndex);
}

Int oldMaterialIndex=1;
Int oldPrevMaterialIndex=1;
Int newMaterialIndex=1;
Int newPrevMaterialIndex=1;
Private void ToolStripMenuItem_NewMaterial_Click (object sender, EventArgs e)
{
If (gridView1 FocusedRowHandle & lt; 0)
{
return;
}

NewPrevMaterialIndex=newMaterialIndex;
NewMaterialIndex=gridView1. FocusedRowHandle;
GridView1. RefreshRow (newPrevMaterialIndex);
GridView1. RefreshRow (newMaterialIndex);
}

Private void gridView1_RowCellStyle (object sender, DevExpress XtraGrid. Views. Grid. RowCellStyleEventArgs e)
{
If (" e.R owHandle & lt; 0)
{
return;
}

If (((" e.R owHandle==oldPrevMaterialIndex) | | (" e.R owHandle==newPrevMaterialIndex)) & amp; &
(e.A ppearance BackColor!=gridView1. Appearance. Row. BackColor))
{
E.A ppearance. BackColor=gridView1. Appearance. Row. BackColor;
}
If ((" e.R owHandle==oldMaterialIndex) & amp; &
(e.A ppearance BackColor!=Color. Red))
{
E.A ppearance. BackColor=Color. Red;
}
Else if ((" e.R owHandle==newMaterialIndex) & amp; &
(e.A ppearance BackColor!=Color. Green))
{
E.A ppearance. BackColor=Color. Green;
}
}

CodePudding user response:

 private void gridView1_RowStyle (object sender, DevExpress. The XtraGrid. Views. Grid. RowStyleEventArgs e) 

This event is also OK
  •  Tags:  
  • C#
  • Related