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;
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;
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.