我正在使用Devexpress TcxGrid,并且我正在尝试获取选定的单元格文本。我的TcxGrid连接到了某种DataSource --我想是DataControler。
我的目标是从整行中的单元格中获取文本,并将其放入以逗号分隔的字符串中。
发布于 2012-03-26 22:27:41
如果您想要多选的值和来自TcxGridDbTableView的值:在我的结果中,行之间没有分隔。
function GetSelectedValuesFrmGrid: String;
var
intSelectLoop,
intRowLoop: Integer;
oTableView: TcxGridDbTableView;
strValue: Variant;
oList: TStringList;
begin
Result:= '';
// Kind Of TableView
if <TcxGrid>.ActiveView is TcxGridDbTableView then
begin
oTableView:= <TcxGrid>.ActiveView as TcxGridDbTableView;
oList:= TStringList.Create();
try
for intSelectLoop:= 0 to oTableView.Controller.SelectedRowCount-1 do
begin
for intRowLoop:= 0 to oTableView.Controller.SelectedRows[intSelectLoop].ValueCount-1 do
begin
strValue:= oTableView.Controller.SelectedRows[intSelectLoop].Values[intRowLoop];
// Value can be Null
if VarIsNull(strValue) then
begin
strValue:= '';
end;
oList.Add(strValue);
end;
end;
Result:= oList.CommaText;
finally
oList.Free;
end;
end;
end;发布于 2012-03-26 22:05:09
网格将有一个DataControler后代。您可以循环浏览DataController中的项目,根据网格的配置方式,DataController中的项目可以对应于网格中显示的各个“列”。也就是说,DataController中的项保留在
这段代码将允许您遍历网格中的每一列,并基于DataController值构建字符串。
var
i: Integer;
DC: TcxCustomDataController;
s: string;
begin
s := '';
DC := <yourgrid>.DataController;
for i := 0 to <yourgrid>.ColumnCount -1 do begin
s := s + vartostr(DC.Values[DC.FocusedRecordIndex, <yourgrid>.Columns[i].Index]) + ',';
end;
if Length(s) > 0 then
s := Copy(s,1,Length(s)-1);
end;发布于 2012-03-26 21:56:19
是否需要选定行中所有单元格的文本?
for I := 0 to cxGridDBTableView.Controller.SelectedRowCount -1 do
for J := 0 to cxGridDBTableView.Controller.SelectedRows[I].ValueCount -1 do
SelectedRowStr := SelectedRowStr + VarToStr(cxGrid1DBTableView1.Controller.SelectedRows[I].Values[J]) + ',';
SelectedRowStr := Copy(SelectedRowStr,1,length(SelectedRowStr)-1);https://stackoverflow.com/questions/9872846
复制相似问题