2014-07-01 22 views
0

我有一個Devexpress網格控件,其中有一個複選框列。我想在用戶選中或取消選中任何一行中的複選框之後獲取複選框值的值。我的問題是我總是得到虛假的價值。我應該使用哪個事件來獲取gridcontrol中的複選框值

如何獲得正確的值?我應該使用什麼事件?

這裏是我的代碼,

private void gvBobin_CellValueChanged(object sender, DevExpress.XtraGrid.Views.Base.CellValueChangedEventArgs e) 
{ 
    setUsageSlipAndProductionEntryRelation(); 
} 


public void setUsageSlipAndProductionEntryRelation() { 

     for (int i = 0; i < gvBobin.RowCount -1; i++) 
     { 
      bool check_ = (bool)gvBobin.GetRowCellValue(i, "CHECK"); 
      if (check_ == true) 
      { 
       ............... 
      } 
      else{ 
       ............... 
      } 
     } 
} 

回答

0

如果你想立即對用戶的動作做出反應,那麼你需要使用GridView.CellValueChanging事件。 GridView.CellValueChanged事件僅在用戶離開單元后觸發。在兩種情況下,要獲取更改的值,必須使用CellValueChangedEventArgs對象e及其Value屬性,並且在獲取值之前必須檢查該列。

private void gvBobin_CellValueChanged(object sender, DevExpress.XtraGrid.Views.Base.CellValueChangedEventArgs e) 
{ 
    if (e.Column.FieldName == "CHECK") 
    { 
     bool check_ = (bool)e.Value; 

     if (check_)//There are no need to write check_ == True 
     //You can use e.RowHandle with gvBobin.GetRowCellValue method to get other row values. 
     //Example: object value = gvBobin.GetRowCellValue(e.RowHandle,"YourColumnName") 
     { 
      //............... 
     } 
     else 
     { 
      //............... 
     } 
    } 
} 

如果要遍歷所有行,請不要使用GridView.RowCount。改用GridView.DataRowCount屬性。

for (int i = 0; i < gvBobin.DataRowCount -1; i++) 
    //............... 
相關問題