Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/algorithm/10.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
DevExpress XtraGrid自定义RowCellStyle事件处理程序和列排序问题_Devexpress_Xtragrid - Fatal编程技术网

DevExpress XtraGrid自定义RowCellStyle事件处理程序和列排序问题

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

My xtraGrid具有自定义样式的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) { }
        }

单击网格列标题以使用网格后,通过排序对行重新排序后,格式最终应用于错误的行。如何解决该问题?

您正在使用提供给您的
e.RowHandle
,并将其转换为
DataSourceHandle
。然后,使用
DataSourceHandle
调用
GetDataRow

但是,
GetDataRow
接受行句柄,而不是数据源句柄。试试这个:

DataRow DR = vw.GetDataRow(e.RowHandle);

感谢您指出额外转换步骤中的错误。