delphidevexpresstcxgrid

TCXGrid unable to edit cell value


I have an application with a CXGrid on a form with a couple of cells. I need to be able to edit the value in a cell and needs to update the value right there on the cell. After reading up, I see that the 2 main properties to set to ensure editing is enabled are:

    GridMainDBTableView1.OptionsData.Editing := True;
    GridMainDBTableView1TotalCount.Editing   := True;

The column here that needs to edit the value is the TotalCount column. When I run the application and try to edit the value, I can see that the cell is editible, as my cursor appears inside the cell, I can hightlight the current integer value that is inside there, but I can never edit it. It never accepts any characters that I type, cannot even delete the current value to type a new value. Nothing more happens apart from the cursor appearing inside the cell, which is also an indication that the read-only is false. but nothing happens, I never get to change the value. Is there anything else I might have missed. I have read through multiple posts, on here and on DevExpress, but cannot get a working solution. Most if not all the solutions indicate that we need to change the values here above.

I have tried even putting in code on show to ensure that the columns editing is indeed set to True etc, but stil nothing changes. The only time I can see I change on the form is when I make it read-only, then my cursor does not appear in the cell anymore.

EDIT: When I query the DB to get the values that needs to populate the grid, the column that I want to change the values in are queried in the following manner:

 ' ROUND(COALESCE(T0.TotalCount,0),T1.QtyDecimal) AS TotalCount, ';

Could this be the reason that it is not edible?


Solution

  • So managed to resolve the issue, by following the advice from Brian above in the comments. So how I resolved the problem was by doing the following.

    I made sure my select uses a standard column, not calculated. Then I passed the Decimal calculations part to the dataset, in this case an ADOQuery. And added my code to the beforePost event.

    procedure TfrmSTK502.qrySTKSTakeSummaryBeforePost(DataSet: TDataSet);
    begin
      if qrySTKSTakeSummary.State in [dsEdit, dsInsert] then
      begin
        // Get QtyDecimal from your function
        var QtyDecimal := getQtyDecimal();
    
        // Round the value
        var RoundedValue := 
      RoundTo(qrySTKSTakeSummary.FieldByName('TotalCount').AsFloat, - QtyDecimal);
    
    // Set the rounded value
        qrySTKSTakeSummary.FieldByName('TotalCount').AsFloat := RoundedValue;
      end;
    end;