首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何从TcxGrid中获取选定的单元格文本?

如何从TcxGrid中获取选定的单元格文本?
EN

Stack Overflow用户
提问于 2012-03-26 21:17:29
回答 3查看 28.6K关注 0票数 3

我正在使用Devexpress TcxGrid,并且我正在尝试获取选定的单元格文本。我的TcxGrid连接到了某种DataSource --我想是DataControler。

我的目标是从整行中的单元格中获取文本,并将其放入以逗号分隔的字符串中。

EN

回答 3

Stack Overflow用户

回答已采纳

发布于 2012-03-26 22:27:41

如果您想要多选的值和来自TcxGridDbTableView的值:在我的结果中,行之间没有分隔。

代码语言:javascript
复制
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;
票数 4
EN

Stack Overflow用户

发布于 2012-03-26 22:05:09

网格将有一个DataControler后代。您可以循环浏览DataController中的项目,根据网格的配置方式,DataController中的项目可以对应于网格中显示的各个“列”。也就是说,DataController中的项保留在

这段代码将允许您遍历网格中的每一列,并基于DataController值构建字符串。

代码语言:javascript
复制
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;
票数 1
EN

Stack Overflow用户

发布于 2012-03-26 21:56:19

是否需要选定行中所有单元格的文本?

代码语言:javascript
复制
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);
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/9872846

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档