Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get selected cell text from TcxGrid?

I'm using Devexpress TcxGrid and I'm trying to get selected cell text. My TcxGrid is connected to some kind of DataSource - I think it is DataControler.

My goal is to get the text from cells in the entire row and place it in string divided with comas.

like image 849
Jacek Kwiecień Avatar asked Dec 13 '25 15:12

Jacek Kwiecień


2 Answers

If you want values with multiselection and from a TcxGridDbTableView: In my result i don't have a separation between rows.

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;
like image 85
Ravaut123 Avatar answered Dec 16 '25 18:12

Ravaut123


You need the text from all cells in selected rows?

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);
like image 30
Agustin Seifert Avatar answered Dec 16 '25 17:12

Agustin Seifert