2011-08-10 67 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。然後,您撥打GetDataRowDataSourceHandle

但是,GetDataRow需要一個行句柄,而不是數據源句柄。試試這個:

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

感謝您指出了額外轉換步驟中的錯誤。 – Tim

+0

很高興幫助你出Tim! – Armbrat