UD2006
06-15-2009, 11:07 PM
I have a DBGrid, datasource and adoconnection and adotable. With an access database, this works fine.
The only 2 questions I have are: in the DBGrid there are multiple records (email addresses), I want it possible to select all the records at once by clicking a button (I have a code but isnt working, first procedure code).
Second question: Those multiple records (email addresses) need to be put into a edit field (separated by a comma) which is on a different form then the grid is, the code I have now, displays the email addresses in a message but instead I want them in a edit field on an other form (second procedure code).
By the way, I have the multiple select on the DBGrid turned true.
First code:
procedure TForm1.Button2Click(Sender: TObject);
begin
with dbGrid1.DataSource.DataSet do
begin
DisableControls;
try
First;
while not Eof do
begin
dbGrid1.SelectedRows.CurrentRowSelected := True;
Next;
end;
finally
EnableControls;
end;
end;
end;
Second code:
procedure TForm1.Button3Click(Sender: TObject);
var I: Integer;
s, delim: string;
begin
s := '';
Delim := ';';
with dbGrid1.DataSource.DataSet do
begin
DisableControls;
try
First;
while not Eof do
begin
if dbGrid1.SelectedRows.CurrentRowSelected then
begin
s := s + FieldByName('A').AsString + Delim;
end;
Next;
end;
finally
EnableControls;
end;
end;
if S <> '' then
Delete(S, Length(s) - Length(Delim)+1, Length(Delim));
ShowMessage(s);
end;
Thanks for any help.
The only 2 questions I have are: in the DBGrid there are multiple records (email addresses), I want it possible to select all the records at once by clicking a button (I have a code but isnt working, first procedure code).
Second question: Those multiple records (email addresses) need to be put into a edit field (separated by a comma) which is on a different form then the grid is, the code I have now, displays the email addresses in a message but instead I want them in a edit field on an other form (second procedure code).
By the way, I have the multiple select on the DBGrid turned true.
First code:
procedure TForm1.Button2Click(Sender: TObject);
begin
with dbGrid1.DataSource.DataSet do
begin
DisableControls;
try
First;
while not Eof do
begin
dbGrid1.SelectedRows.CurrentRowSelected := True;
Next;
end;
finally
EnableControls;
end;
end;
end;
Second code:
procedure TForm1.Button3Click(Sender: TObject);
var I: Integer;
s, delim: string;
begin
s := '';
Delim := ';';
with dbGrid1.DataSource.DataSet do
begin
DisableControls;
try
First;
while not Eof do
begin
if dbGrid1.SelectedRows.CurrentRowSelected then
begin
s := s + FieldByName('A').AsString + Delim;
end;
Next;
end;
finally
EnableControls;
end;
end;
if S <> '' then
Delete(S, Length(s) - Length(Delim)+1, Length(Delim));
ShowMessage(s);
end;
Thanks for any help.