delphi 列出DBGridEH被选中的值

//列出DBGridEH被选中的值
procedure TForm1.N4Click(Sender: TObject);
 Var
    I:Integer;
begin
   for I := 0 to DBGridEh4.SelectedRows.Count-1 do
      begin
        DBGridEh4.DataSource.DataSet.GotoBookmark(pointer(DBGridEh4.SelectedRows.Items[i]));
        Memo1.Lines.Add(DBGridEh4.Fields[1].AsString);
      End;

end; 



扩展:

选中多行判断值,先做一个判断

首先要打开 dbgrideh属性 中的多重选择 options->dgmultiselect

 

procedure TForm3.N5Click(Sender: TObject);

var

 i: Integer;

begin

 if DBGridEh1.SelectedRows.Count>0 then

   with DBGridEh1.DataSource.DataSet do

     for i:=0 to DBGridEh1.SelectedRows.Count-1 do

     begin

       GotoBookmark(pointer(DBGridEh1.SelectedRows.Items[i]));

       Listbox1.Items.Add(Fields[0].AsString);

     end;

 

end;


你可能感兴趣的:(DBGRIDEH)