在这种方法中,如果仅未选择该行,则需要写附加条件,然后使底色变淡。我该怎么办?
private void docsActiveBandedGridView_CustomDrawCell(object sender, DevExpress.XtraGrid.Views.Base.RowCellCustomDrawEventArgs e)
{
DataRow dtrow = docsActiveBandedGridView.GetDataRow(e.RowHandle);
if (dtrow != null && executeDocIDs.Contains(decimal.Parse(dtrow["ID"].ToString())))
e.Appearance.BackColor = Color.Thistle;
}
答案 0 :(得分:1)
您可以使用GridView.RowCellStyle事件来实现自己的行样式。
private void docsActiveBandedGridView_RowCellStyle(object sender, RowCellStyleEventArgs e)
{
//If row is selected or focused then do nothing
if(view.IsRowSelected(e.RowHandle) || view.FocusedRowHandle == e.RowHandle)
return;
DataRow dtrow = docsActiveBandedGridView.GetDataRow(e.RowHandle);
if (dtrow != null && executeDocIDs.Contains(decimal.Parse(dtrow["ID"].ToString())))
e.Appearance.BackColor = Color.Thistle;
}
要避免在现有代码中绘制选定的行或重点突出的行,只需检查选定的行或重点突出的行即可,不要忘记设置e.Handled= true
:
private void docsActiveBandedGridView_CustomDrawCell(object sender, DevExpress.XtraGrid.Views.Base.RowCellCustomDrawEventArgs e)
{
//If row is selected or focused then do nothing
if(view.IsRowSelected(e.RowHandle) || view.FocusedRowHandle == e.RowHandle)
return;
DataRow dtrow = docsActiveBandedGridView.GetDataRow(e.RowHandle);
if (dtrow != null && executeDocIDs.Contains(decimal.Parse(dtrow["ID"].ToString())))
e.Appearance.BackColor = Color.Thistle;
e.Handled = true; //Do not forget to set Handled property to true to know the grid that you handled painting of the grid cell
}
参考文献:
How to customize the FocusedRow and SelectedRow appearance in the GridView
GridView Color Selected Rows
Focused Row Appearance
答案 1 :(得分:0)
这应该告诉您是否选择了该行:
docsActiveBandedGridView.GetSelectedRows().Contains(e.RowHandle)
如果您没有启用多选(docsActiveBandedGridView.OptionsSelection.MultiSelect = false
),那么使用集中的行句柄实际上可能会更好,因为知道突出显示的行不会超过:
docsActiveBandedGridView.FocusedRowHandle == e.RowHandle