繁体   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