dxDBGrid的使用有些问题,急(100分)

  • 主题发起人 卖女孩的小火柴之二
  • 开始时间

卖女孩的小火柴之二

Unregistered / Unconfirmed
GUEST, unregistred user!
我现在要用dxDBGrid控件,当它选中其中的几行的时候,我通过那个性质可以取到这几行的任何一行的列的值。我对这个控件不是很熟,谢谢!
 
转一段代码给你:
procedure TCaptoolsMainForm.GetRecordsBookmarkList(AView:
TcxGridDBBandedTableView;
aBookMarkList: TList);
var
AFocusedRecord: TcxCustomGridRecord;
ADataSet: TDataSet;
I: Integer;
begin
aBookMarkList.Clear;
if not Assigned(AView) then
Exit;
ADataSet := AView.DataController.DataSet;
AView.begin
Update;
try
AFocusedRecord := AView.Controller.FocusedRecord;
for I := 0 to AView.Controller.SelectedRecordCount - 1do
begin
AView.Controller.SelectedRecords.Focused := True;
aBookMarkList.Add(TBookMarkList(ADataSet.GetBookmark));
;
end;
if Assigned(AFocusedRecord) then
AFocusedRecord.Focused := True;
finally
AView.EndUpdate;
end;
end;

主要通过:AView.Controller.SelectedRecords.Focused := True;来定位到所在行,然后直接读取相应的数据集中的数据即可.
 
好像和我说的不一样哦!
 
你可以通过AView.Controller.SelectedRecords.Focused := True来定位到你所选的行,然后用AView.DataController.DataSet.FieldByName('fieldname').AsString来取到该列的值.
 
Delphi(Pascal) code
for I := 0 to dxDBGrid1.Count - 1do
if dxDBGrid1.Items.Selected then
begin
Field1 := dxDBGrid1.Items.Strings[0];
//第一列的值
end;

delphi的dbgrid就有这个功能
Delphi(Pascal) code
procedure TForm1.Button1Click(Sender: TObject);
var
i, j: Integer;
s: string;
begin
if DBGrid1.SelectedRows.Count>0 then
with DBGrid1.DataSource.DataSetdo
for i:=0 to DBGrid1.SelectedRows.Count-1do
begin
GotoBookmark(pointer(DBGrid1.SelectedRows.Items));
for j := 0 to FieldCount-1do
begin

if (j>0) then
s:=s+', ';
s:=s+Fields[j].AsString;
end;
Listbox1.Items.Add(s);
s:= '';
end;
end;
 
顶部