Retain the value entered in the cell of DevExpress Xtragrid

devexpressxtragrid

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

I enter some value into the first cell of the grid and if i go to second cell , the value entered in the first cell disappears.

How to retain the value entered in the cell ?

Best Answer

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