[英]Which event should I use to get the checkbox value which is in gridcontrol
I have a Devexpress gridcontrol that has a checkbox column in it. 我有一个Devexpress gridcontrol,其中具有一个复选框列。 I am trying to get the value of the checkbox value after user checks or unchecks one of the checkbox in any row.
我试图在用户选中或取消选中任何行中的复选框之一后获取复选框值的值。 My problem is I am getting the always getting false value.
我的问题是,我总是得到虚假的价值。
How can I get the correct value? 如何获得正确的值? what event should I use?
我应该使用什么活动?
here is my code, 这是我的代码,
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{
...............
}
}
}
If you want to immediately react to user actions, then you need to use GridView.CellValueChanging
event. 如果要立即对用户操作做出反应,则需要使用
GridView.CellValueChanging
事件。 GridView.CellValueChanged
event is fired only after user leaves the cell. 仅在用户离开单元格后才触发
GridView.CellValueChanged
事件。 In both cases to get the changed value you must use CellValueChangedEventArgs
object e
and its Value
property and before getting value you must to check the column. 在这两种情况下,要获取更改后的值,都必须使用
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
{
//...............
}
}
}
If you want to iterate through all rows then don't use GridView.RowCount
. 如果要遍历所有行,请不要使用
GridView.RowCount
。 Use GridView.DataRowCount
property instead. 请改用
GridView.DataRowCount
属性。
for (int i = 0; i < gvBobin.DataRowCount -1; i++)
//...............
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.