【问题标题】:DevExpress XtraGrid custom RowCellStyle eventhandler and column sorting problemDevExpress XtraGrid 自定义 RowCellStyle 事件处理程序和列排序问题
【发布时间】:2011-08-10 16:02:26
【问题描述】:

我的 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) { }
        }

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

【问题讨论】:

    标签: devexpress xtragrid


    【解决方案1】:

    您将获取给您的e.RowHandle 并将其转换为DataSourceHandle。然后,您使用DataSourceHandle 调用GetDataRow

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

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

    【讨论】:

    • 感谢您指出额外转换步骤中的错误。
    猜你喜欢
    • 2012-10-29
    • 2020-02-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-11-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多