开发者

Retain the value entered in the cell of DevExpress Xtragrid

开发者 https://www.devze.com 2022-12-17 00:19 出处:网络
I am using DevExpress Xtragrid control in my C#.net windows application. I enter some value into the first cell of the gr开发者_高级运维id and if i go to second cell , the value entered in the first

I am using DevExpress Xtragrid control in my C#.net windows application.

I enter some value into the first cell of the gr开发者_高级运维id and if i go to second cell , the value entered in the first cell disappears.

How to retain the value entered in the cell ?


I am assuming that you are using this for an unbound column in a gridView (Xtragrid), first step is make sure to go to the column properties, and change the UnboundType property value to the datatype that you will be entering into that column, example below uses double.

Assign the CustomUnboundColumnData event to your gridView. Make sure that you declare a class level variable (named _userEnteredData in code sample below) to hold the value that you are entering into your gridView, then add the following piece of code, but make sure that you change the names to match your gridView and variable names:

Class level variable declaration:

private double _userEnteredData = 0;

Now the event:

private void gridView1_CustomUnboundColumnData(object sender, DevExpress.XtraGrid.Views.Base.CustomColumnDataEventArgs e)
{
    if (e.Column == gridColumn_YourColumn && e.IsSetData)
    {
        _userEnteredData = Convert.ToDouble(e.Value);
    }
    else if (e.Column == gridColumn_YourColumn && e.IsGetData)
    {
        e.Value = _userEnteredData;
    }
}

I hope this helps.

You can get further details from here: http://documentation.devexpress.com/#WindowsForms/CustomDocument1477


Few possibilities:

  • check FieldName property of edited column. Maybe there is a typo, so grid does not pass your entered value to underlying datasource
  • property that is bound to column must have public setter. If there is only getter, grid also won't be capable to store entered value
  • check ColumnOptions.ReadOnly property in grid column - must be set to false

Hope this helps

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号