this.gridView1.Appearance.FocusedRow.BackColor = System.Drawing.Color.DarkSalmon; this.gridView1.Appearance.FocusedRow.Font = new System.Drawing.Font("Tahoma", 9F, System.Drawing.FontStyle.Bold); this.gridView1.Appearance.FocusedRow.ForeColor = System.Drawing.Color.White; this.gridView1.Appearance.FocusedRow.Options.UseBackColor = true; this.gridView1.Appearance.FocusedRow.Options.UseFont = true; this.gridView1.Appearance.FocusedRow.Options.UseForeColor = true; this.gridView1.Appearance.HideSelectionRow.BackColor = System.Drawing.Color.DarkSalmon; this.gridView1.Appearance.HideSelectionRow.Font = new System.Drawing.Font("Tahoma", 9F, System.Drawing.FontStyle.Bold); this.gridView1.Appearance.HideSelectionRow.ForeColor = System.Drawing.Color.White; this.gridView1.Appearance.HideSelectionRow.Options.UseBackColor = true; this.gridView1.Appearance.HideSelectionRow.Options.UseFont = true; this.gridView1.Appearance.HideSelectionRow.Options.UseForeColor = true;
效果:
DevExpress為.NET平台提供了很多優秀美觀的Ui控件,給數據和圖表展示帶來了極大的便捷性。這里使用的是DevExpress2015版本,安裝起來也很方便,只要運行DevExpressUniversalTrialComplete-20151209.exe,一路默認即可。
當然由於剛開始接觸,也遇到一些問題。比如DevExpress GridView控件,是用來展示表格樣式的數據,其內嵌到gridControl組件中,只要在它的列屬性中“FieilName”屬性設置好與數據庫關聯的字段名稱,就可以很好的展示數據庫記錄了:
GridView顯示數據行背景默認是白色的,為了有時能突出重點,需要設置為其他顏色。參考一些資料,添加RowStyle事件:
this.gridView1.RowStyle += new DevExpress.XtraGrid.Views.Grid.RowStyleEventHandler(this.gridView1_RowStyle);
然后在gridView1_RowStyle函數中根據不同的字段名稱顯示不同顏色:
private void gridView1_RowStyle(object sender, DevExpress.XtraGrid.Views.Grid.RowStyleEventArgs e)
{
DataRow dr = gridView1.GetDataRow(e.RowHandle);
if (dr != null)
{
if (dr["GasType"].ToString() == "LNG")
{
e.Appearance.BackColor = Color.LightPink;
}
else
{
if (dr["GasType"].ToString() == "CNG")
{
e.Appearance.BackColor = Color.GreenYellow;
}
}
}
}
顯示結果如下:
但這里有個問題,就是選中行還是灰色的,顯然里面的設置對於選中行並沒有起作用。還得對其進行其他處理,運行“Run Designer”設置:
在“Appearance”菜單里設置“FocusedRow”參數和“HideSelectionRow”參數的BackColor為暗紅色:
之后再運行程序,就發現表中默認選中的行變為了暗紅色: