介绍一些经常使用的gridcontrol设置。字体
一、设置隔行变色。首先设置显示隔行变色,步骤:OptionsView-->EnableAppearanceEvenRow-->true和OptionsView-->EnableAppearanceOddRow-->true;而后设置奇数行和偶数行样式颜色等:Appearance-->EvenRow和Appearance-->OddRow。设计完成后,设计器出现隔行变色效果,如图:spa
二、设置奇偶行样式时,会看到其余行样式。Appearance-->FoucsedRow就是焦点行颜色,设置后可突出显示焦点行样式,如图所示:设计
三、设置显示值,有个两种方法。第一种能够在如图所示地方设置,列显示出来就会加上单位元;用的最多的通常是设置日期样式yyyy年MM月dd日:3d
第二种可以使用代码改变,代码以下:code
/// <summary> /// 改变显示值 /// </summary> private void gridView1_CustomColumnDisplayText(object sender, DevExpress.XtraGrid.Views.Base.CustomColumnDisplayTextEventArgs e) { if (e.Column.FieldName == "A3") { if (e.Value.ToString() == "1") e.DisplayText = "男"; else e.DisplayText = "女"; } }
四、有时表格列太多,须要拖动查看,可是又但愿某些列能始终固定不移动。这个时候就能够设置该列为固定列了,属性如图所示:blog
五、运行效果图:get
附源码:http://files.cnblogs.com/files/starksoft/demo006.rar源码
附加内容:根据条件改变行的样式(字体颜色、背景颜色、渐变色)it
private void gridView1_RowStyle(object sender, DevExpress.XtraGrid.Views.Grid.RowStyleEventArgs e) { int hand = e.RowHandle;//行号 if(hand<0) { return; } DataRow dr = gridView1.GetDataRow(hand); if (dr == null) return; //int selectedHandle = gridView1.GetSelectedRows()[hand]; if (gridView1.GetRowCellValue(hand, "CODE").ToString().Contains("5")) { e.Appearance.ForeColor = Color.Red;//字体颜色 e.Appearance.BackColor=Color.Linen;//行背景颜色 //e.Appearance.BackColor2 = Color.Blue;//渐变颜色 } }