cxgrid多选获取记录。不需要设置KeyFieldName
procedure CopyGridRecordToJsn(pvDataSet: TcxGridDBTableView; pvValueJsn:
ISuperObject);
var
i, j: Integer;
lvField: TcxGridDBColumn;
lvItem: ISuperObject;
begin
with pvDataSet, DataController do
begin
for i := 0 to Controller.SelectedRecordCount - 1 do
begin
lvItem := SO();
try
for j := 0 to pvDataSet.ColumnCount - 1 do
begin
lvField := pvDataSet.Columns[j];
if lvField.DataBinding.ValueType <> 'Object' then
begin
lvItem.S[LowerCase(lvField.DataBinding.FieldName)] :=
VarToStrDef(GetValue(Controller.SelectedRecords[i].RecordIndex, j), '');
end;
end;
pvValueJsn.O['select.value'] := lvItem;
pvValueJsn.O['select.values[]'] := lvItem;
finally
lvItem := nil;
end;
end;
end;
end;
ISuperObject);
var
i, j: Integer;
lvField: TcxGridDBColumn;
lvItem: ISuperObject;
begin
with pvDataSet, DataController do
begin
for i := 0 to Controller.SelectedRecordCount - 1 do
begin
lvItem := SO();
try
for j := 0 to pvDataSet.ColumnCount - 1 do
begin
lvField := pvDataSet.Columns[j];
if lvField.DataBinding.ValueType <> 'Object' then
begin
lvItem.S[LowerCase(lvField.DataBinding.FieldName)] :=
VarToStrDef(GetValue(Controller.SelectedRecords[i].RecordIndex, j), '');
end;
end;
pvValueJsn.O['select.value'] := lvItem;
pvValueJsn.O['select.values[]'] := lvItem;
finally
lvItem := nil;
end;
end;
end;
end;