I have a Devexpress gridcontrol that has a checkbox column in it. 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.CellValueChanged
event is fired only after user leaves the cell. 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.
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
. Use GridView.DataRowCount
property instead.
for (int i = 0; i < gvBobin.DataRowCount -1; i++)
//...............
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.