1

I read some data from a table and copy the data to a column in a cxGrid and then I want to update this directly to the database. Hows that possible?

I've tried using setEditValue but that one requires a parameter of type:

TcxDataEditValueSource = (evsValue, evsText, evsKey);

And I can' find this type. In some example from DeveloperExpress they set it to 1 but that doesn't work. It's wrong type say's the compiler.

This is the code I used to make the data into the grid but haow can I make it update the dataset?

var
  RecIDx,
    ColIdx,
    sorNo,
    RecID,
    i: integer;
  AB,
    AT: double;

begin
  try
    // Get marked row and column
    RecIDx := grGeneralInfoMallDBTableView1.Controller.SelectedRecords[0]
      .RecordIndex;
    ColIdx := grGeneralInfoMallDBTableView1.DataController.GetItemByFieldName
      ('ID').Index;

    // Get SortingOrderNo
    sorNo := grGeneralInfoMallDBTableView1.DataController.Values
      [RecIDx, ColIdx];

    // Get AB and AT from SortingOrderRow with highest priority (lowest number)
    dmsSortOrder.sq_Get_AB_AT.Active := false;
    dmsSortOrder.sq_Get_AB_AT.ParamByName('sorNo').AsInteger := sorNo;
    dmsSortOrder.sq_Get_AB_AT.Active := true;
    dmsSortOrder.sq_Get_AB_AT.First;
    if dmsSortOrder.sq_Get_AB_AT.EOF then
    begin
      showMessage('ERROR! Could not find record for sortorder: ' +
        intToStr(sorNo));
      exit;
    end;
    // Copy AT and BT to the grid.
AT := dmsSortOrder.sq_Get_AB_AT.FieldByName('AT').AsFloat;
AB := dmsSortOrder.sq_Get_AB_AT.FieldByName('AB').AsFloat;


// Set the cell value
grGeneralInfoMallDBTableView1.DataController.DataSource.DataSet.Edit;
ColIdx := grGeneralInfoMallDBTableView1.DataController.GetItemByFieldName
  ('AT').Index;
grGeneralInfoMallDBTableView1.DataController.SetValue(RecIDx,ColIdx, AT);
ColIdx := grGeneralInfoMallDBTableView1.DataController.GetItemByFieldName
  ('AB').Index;
grGeneralInfoMallDBTableView1.DataController.SetValue(RecIDx,ColIdx, AB);
grGeneralInfoMallDBTableView1.DataController.DataSource.DataSet.Post;
  finally
  end;

end;
larand
  • 773
  • 1
  • 9
  • 26
  • 2
    If your GridView is data-bound you should be able to simply update the fields of the underlying `TDataSet`. – nil Oct 19 '17 at 09:42
  • You really wake me up! I changed the code above to show how I did it. Simple and I didn't need to add data to the grid in this way. Thank's! – larand Oct 19 '17 at 10:17
  • 1
    Your welcome. By the way, you now changed your question to be no question anymore. It would be better to revert this change to the question. It is absolutely fine to post your own answer with how you solved it. – nil Oct 19 '17 at 10:18
  • You should do what @nil says. – MartynA Oct 19 '17 at 10:52

1 Answers1

1

This is how I solved it:

    var
  RecIDx,
    ColIdx,
    sorNo,
    RecID,
    i: integer;
  AB,
    AT: double;

begin
  try
    // Get marked row and column
    RecIDx := grGeneralInfoMallDBTableView1.Controller.SelectedRecords[0]
      .RecordIndex;
    ColIdx := grGeneralInfoMallDBTableView1.DataController.GetItemByFieldName
      ('ID').Index;

// Get SortingOrderNo
sorNo := grGeneralInfoMallDBTableView1.DataController.Values
  [RecIDx, ColIdx];

// Get AB and AT from SortingOrderRow with highest priority (lowest number)
dmsSortOrder.sq_Get_AB_AT.Active := false;
dmsSortOrder.sq_Get_AB_AT.ParamByName('sorNo').AsInteger := sorNo;
dmsSortOrder.sq_Get_AB_AT.Active := true;
dmsSortOrder.sq_Get_AB_AT.First;
if dmsSortOrder.sq_Get_AB_AT.EOF then
begin
  showMessage('ERROR! Could not find record for sortorder: ' +
    intToStr(sorNo));
  exit;
end;
// Copy AT and BT to the grid.
AT := dmsSortOrder.sq_Get_AB_AT.FieldByName('AT').AsFloat;
AB := dmsSortOrder.sq_Get_AB_AT.FieldByName('AB').AsFloat;

grGeneralInfoMallDBTableView1.DataController.DataSource.DataSet.Edit;
grGeneralInfoMallDBTableView1.DataController.DataSource.DataSet.FieldByName('AT').Value := AT;
grGeneralInfoMallDBTableView1.DataController.DataSource.DataSet.FieldByName('AB').Value := AB;
grGeneralInfoMallDBTableView1.DataController.DataSource.DataSet.Post;
  finally
  end;

end;
larand
  • 773
  • 1
  • 9
  • 26