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

标签 devexpress xtragrid

我的 xtraGrid 有一个自定义样式的事件监听器:

  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 .然后,您调用GetDataRowDataSourceHandle .

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

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

关于DevExpress XtraGrid 自定义 RowCellStyle 事件处理程序和列排序问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7013988/

相关文章:

c# - 使用接口(interface)将行添加到 XtraGrid

c# - MVC 中的模态编辑

devexpress - 如何在计算字段xtrareport中获取姓名月份

button - 如何通过 gridcell 中的存储库按钮获取 xtragrid 行索引?

c# - 将自定义集合转换为 DataRow

c# - 向 DevExpress GridView 添加行

c# - ASPxCombobox,允许用户输入和下拉选择

c# - DevExpress XtraGrid v12.2 GetSelectedRow

c# - 更改 XtraGrid 中的数据源