My xtraGrid has a custom style eventlistener:
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) { }
}
After clicking on a grid column header to resort the grid, the formatting ends up applied to the wrong rows after the rows have been reordered by the sort. How to address that problem?
You are taking the e.RowHandle
given to you and converting it to a DataSourceHandle
. Then, you are calling GetDataRow
with the DataSourceHandle
.
However, GetDataRow
takes in a row handle, not a data source handle. Try this:
DataRow DR = vw.GetDataRow(e.RowHandle);