...

View Full Version : Multiple records from multiple rows in a single edit field Delphi



UD2006
06-16-2009, 12:07 AM
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.

AlexV
06-16-2009, 08:14 PM
Select all code (works here):

dbGrid1.SelectedRows.Clear;
with dbGrid1.DataSource.DataSet do
begin
DisableControls;
First;
try
while not EOF do
begin
dbGrid1.SelectedRows.CurrentRowSelected := True;
Next;
end;
finally
EnableControls;
end;
end;

Email list code (untested):

with dbGrid1.DataSource.DataSet do
begin
DisableControls;
First;
try
while not EOF do
begin
if dbGrid1.SelectedRows.CurrentRowSelected then
s := s + FieldByName('A').AsString + Delim;
Next;
end;
finally
EnableControls;
end;
end;

UD2006
06-22-2009, 10:45 AM
Select all code (works here):

dbGrid1.SelectedRows.Clear;
with dbGrid1.DataSource.DataSet do
begin
DisableControls;
First;
try
while not EOF do
begin
dbGrid1.SelectedRows.CurrentRowSelected := True;
Next;
end;
finally
EnableControls;
end;
end;

Email list code (untested):

with dbGrid1.DataSource.DataSet do
begin
DisableControls;
First;
try
while not EOF do
begin
if dbGrid1.SelectedRows.CurrentRowSelected then
s := s + FieldByName('A').AsString + Delim;
Next;
end;
finally
EnableControls;
end;
end;

Sorry for the late respons, but that solved my problem, many thanks.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum