DevExpress XtraGrid自定义RowCellStyle事件处理程序和列排序问题
My xtraGrid具有自定义样式的eventlistener:DevExpress XtraGrid自定义RowCellStyle事件处理程序和列排序问题,devexpress,xtragrid,Devexpress,Xtragrid,My xtraGrid具有自定义样式的eventlistener: FooGridView.RowCellStyle += new DevExpress.XtraGrid.Views.Grid.RowCellStyleEventHandler(FooGridView_RowCellStyle); private void FooGridView_RowCellStyle(object sender, DevExpress.XtraGrid.Views.Grid.RowCellStyl
FooGridView.RowCellStyle += new DevExpress.XtraGrid.Views.Grid.RowCellStyleEventHandler(FooGridView_RowCellStyle);
private void FooGridView_RowCellStyle(object sender, DevExpress.XtraGrid.Views.Grid.RowCellStyleEventArgs e)
{
DevExpress.XtraGrid.Views.Grid.GridView vw = (sender as DevExpress.XtraGrid.Views.Grid.GridView);
try
{
DataRow DR = vw.GetDataRow(vw.GetRowHandle(e.RowHandle));
if (**some condition based on one or more values in the DataRow**)
{
e.Appearance.Font = new System.Drawing.Font(e.Appearance.Font, System.Drawing.FontStyle.Strikeout);
e.Appearance.ForeColor = Color.LightGray;
}
else
{
e.Appearance.Font = new System.Drawing.Font(e.Appearance.Font, System.Drawing.FontStyle.Regular);
e.Appearance.ForeColor = Color.Black;
}
}
catch (Exception ex) { }
}
单击网格列标题以使用网格后,通过排序对行重新排序后,格式最终应用于错误的行。如何解决该问题?您正在使用提供给您的
e.RowHandle
,并将其转换为DataSourceHandle
。然后,使用DataSourceHandle
调用GetDataRow
但是,GetDataRow
接受行句柄,而不是数据源句柄。试试这个:
DataRow DR = vw.GetDataRow(e.RowHandle);
感谢您指出额外转换步骤中的错误。