GridView控件綁定事件:
gridView_SampleData.CustomDrawCell += gridView_SampleData_CustomDrawCell;
根據自定義邏輯來改變行屬性,例子是判斷某個單元格的Is duplicated列是否為yes,若是,則將行標記為黃色。
//自定義畫某行 private void gridView_SampleData_CustomDrawCell(object sender, DevExpress.XtraGrid.Views.Base.RowCellCustomDrawEventArgs e) { if (gridView_SampleData.GetRow(e.RowHandle) == null) return; else { //隱藏標記行 if (gridView_SampleData.Columns["Is duplicated"] != null) { gridView_SampleData.Columns["Is duplicated"].VisibleIndex = -1; //獲取所在行指定列的值 string duplicated = gridView_SampleData.GetRowCellValue(e.RowHandle, "Is duplicated").ToString(); //設置此行的背景顏色 if (duplicated == "yes") e.Appearance.BackColor = Color.Yellow; } } }