Devexpress TcxGrid を使用しており、選択したセル テキストを取得しようとしています。私の TcxGrid はある種の DataSource に接続されています - 私はそれが DataControler だと思います。
私の目標は、行全体のセルからテキストを取得し、それをカンマで区切られた文字列に配置することです。
Devexpress TcxGrid を使用しており、選択したセル テキストを取得しようとしています。私の TcxGrid はある種の DataSource に接続されています - 私はそれが DataControler だと思います。
私の目標は、行全体のセルからテキストを取得し、それをカンマで区切られた文字列に配置することです。
複数選択の値と 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;
グリッドには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;
選択した行のすべてのセルのテキストが必要ですか?
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);