2013-09-25 36 views
3

我想設置devexpress winforms網格的背景顏色。如何在devexpress中設置背景顏色XtraGrid

這是我打電話的方法。

在形式負載..

LoadCodes(); - 返回在gridView rowstyle方法中使用的數據集。

gridView1.RefreshData();

private void gridView1_RowStyle(object sender, RowStyleEventArgs e) 
{ 
    string code=string.Empty; 
    for (int i = 0; i <= ds.Tables[0].Rows.Count - 1; i++) 
    { 
    code = View.GetRowCellDisplayText(e.RowHandle, View.Columns["code"]); 
    if (code.Trim() == ds.Tables[0].Rows[i]["code"].ToString().Trim()) 
    { 
     e.Appearance.BackColor = Color.LightBlue; 
     e.Appearance.BackColor2 = Color.WhiteSmoke; 
    } 
    } 

} 

如何處理這或有任何其他方式來處理呢?

問題:代碼不會引發任何錯誤,但我沒有看到行 自動獲得背景色,在窗體加載後, 然而,當我在網格的任何行單擊(後窗體被加載,網格數據可見),然後我看到背景顏色。

回答

1

你必須告訴的DevExpress其外觀性能應該通過e.Appearance.Options

設置它在你的情況下生效e.Appearance.Options.UseBackColor = true

有關詳細信息,請參閱:http://documentation.devexpress.com/#windowsforms/DevExpressUtilsAppearanceOptionsMembersTopicAll

注意:當你有定義樣式爲EvenRowOddRow您也必須設置e.HighPriority(請參閱:http://documentation.devexpress.com/#windowsforms/DevExpressXtraGridViewsGridRowStyleEventArgs_HighPrioritytopic

1

你基本上需要設置默認顏色爲GridView像下面,

gridView.Appearance.Row.BackColor = Color.Black; 
gridView.Appearance.Row.BorderColor = Color.Black; 
gridView.Appearance.Row.ForeColor = Color.White; 

上面,我們正在設置外觀行,然後做SelectedRow,FocusedRow,FocusedCell和GroupRow相同。這將使所有行都具有黑色背景並具有白色前景。

現在如果您想覆蓋特定單元格的默認顏色,請覆蓋RowCellStyle事件https://documentation.devexpress.com/#WindowsForms/DevExpressXtraGridViewsGridGridView_RowCellStyletopic