簡體   English   中英

我應該使用哪個事件來獲取gridcontrol中的復選框值

[英]Which event should I use to get the checkbox value which is in gridcontrol

我有一個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{
                ...............
            }
        }
}

如果要立即對用戶操作做出反應,則需要使用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++)
    //...............

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM