2011-08-10 22 views
4

私xtraGridは、カスタムスタイルのEventListenerがありますDevExpress社XtraGridカスタムRowCellStyleのイベントハンドラと列の並べ替え問題

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

グリッドを訴えるために、グリッドの列ヘッダをクリックした後、書式設定は、後に間違った行に適用して終わります並べ替えによって行が並べ替えられました。その問題に対処するには?

答えて

5

あなたはe.RowHandleを受け取ってDataSourceHandleに変換しています。その後、DataSourceHandleGetDataRowと呼んでいます。

ただし、GetDataRowはデータハンドルではなく行ハンドルを取ります。試してみてください:

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

この余分な変換ステップでエラーを指摘していただきありがとうございます。 – Tim

+0

あなたを助けてくれるのがティム! – Armbrat

関連する問題