參考文檔:Customizing the Appearances of Individual Column and Band Headers
定製外觀也可以被分配到各個柱和帶 頭。這種技術與上述類似。若要 指定用於繪製單個列的外觀設置 標題,請使用該列的GridColumn.AppearanceHeader屬性。 樂隊的模擬是GridBand.AppearanceHeader屬性。
視圖中所有列標題的外觀設置由GridViewAppearances.HeaderPanel屬性指定。 AppearanceHeader屬性提供了單個列標題的外觀設置。
列標題也可以使用GridView.CustomDrawColumnHeader事件自定義繪製。
方法1:
gridControl1.LookAndFeel.Style = DevExpress.LookAndFeel.LookAndFeelStyle.Flat;
gridControl1.LookAndFeel.UseDefaultLookAndFeel = false; // <<<<<<<<
gridviewActiv.Columns[0].Appearance.HeaderPanel.Options.UseBackColor = true;
gridviewActiv.Columns[0].Appearance.HeaderPanel.BackColor = System.Drawing.Color.White;
方法2:
void gridView1_CustomDrawColumnHeader(object sender, ColumnHeaderCustomDrawEventArgs e) {
if (e.Column == null) return;
if (e.Column == colGrowth) //condition to paint specific column
{
e.Appearance.BackColor = Color.Red;
e.Handled = true; // must set flag to true to tell grid that it has been customized.
}
}
來源:Applying Styles to Group Rows
實施例:
using DevExpress.XtraGrid.Views.Grid;
using DevExpress.XtraGrid.Columns;
using DevExpress.Utils;
private void Form1_Load(object sender, System.EventArgs e) {
// ...
InitStyles();
}
private void InitStyles() {
GridView View = gridControl1.MainView as GridView;
// Customize the column headers' appearances.
AppearanceObject appCountry = View.Columns["Country"].AppearanceHeader;
appCountry.BackColor = Color.AntiqueWhite;
appCountry.BackColor2 = Color.Snow;
View.Columns["City"].AppearanceHeader.BackColor = Color.LightSalmon;
// Set the View's painting syle.
View.PaintStyleName = "UltraFlat";
}
注:
使用外觀設置,可以在GridControls的LookAndFeel屬性設置爲Flat,UltraFlat或Style3D值時更改列標題的背景顏色。如果您想更改皮膚列標題的顏色,您應該創建自己的皮膚。另一個解決方案是在CustomDrawColumnHeader事件處理程序中手動繪製列標題。此事件允許您按需要繪製列標題,從而不依賴網格的繪畫。
感謝它正在工作,但這是工作,如果列有行。 (如果列爲空,則爲空引用錯誤),但它正在處理我。感謝nempoBu4 – onur