DevExpress PivotGrid - editing with LookUpEdit repository item

1.1k Views Asked by At

I'm using a PivotGrid to display string values as my Data area value. My first problem was that, because the data value is a string, all cells contained zeros when the pivot is performed. However, I fixed that by changing the column aggregate type to max from sum.

Now, my problem. I have a SQL proc that takes a type parameter and returns a list of possible values for the type. Each 'column' in the pivotgrid is one of these types. I am showing only the string value of the type, but I have the int value (which needs to be passed to the proc) in the grid's datasource as well as a separate field. Now, I can have any number of columns, and would need to be able to edit a cell with a LookUpEdit repository item. The list of values returned for each cell would be dictated by the column I'm busy with. Therefore, I need to dynamically create lookupedits for each cell on the fly, passing the cell's type ID through as a parameter to correctly fill the dropdown.

I'm able to do that, but there is no link between the ID in the lookup and the ID on the grid. When I drop down, I can select a value from the lookup, but I don't know how to bind the value I selected to the specific field in the grid's datasource (the cell's value just switches back to what it was before I dropped down). I think the main problem is that I'm displaying the string value in the data area of the grid and not a numeric value. The users of this screen will need the string value to know what they're doing, and will need to be able to select a new string value from the lookups to edit the underlying table's int value.

I hope this is clear enough. If you need any more detail, please feel free to ask.

Thanks!

1

There are 1 best solutions below

0
On

You can use PivotDrillDownDataSource to get all IDs of grid's data source. Subscribe to PivotGridControl.EditValueChanged event, update your grid's data source and refresh PivotGridControl by using PivotGridControl.RefreshData method:

private void pivotGridControl_EditValueChanged(object sender, EditValueChangedEventArgs e)
{
    var drillDown = e.CreateDrillDownDataSource();

    foreach (PivotDrillDownDataRow row in drillDown)
    {
        var id = row["Your ID Column"];

        //Get your Data Source entity by id

        var value = e.Editor.EditValue;

        //Set value to your Data Source entity
    }

    pivotGridControl.RefreshData();
}