Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    Regular Coder
    Join Date
    Jul 2007
    Location
    Velsen Noord, Netherlands
    Posts
    206
    Thanks
    6
    Thanked 0 Times in 0 Posts

    Multiple records from multiple rows in a single edit field Delphi

    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:
    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:
    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.

  • #2
    Regular Coder
    Join Date
    Oct 2008
    Posts
    214
    Thanks
    5
    Thanked 22 Times in 22 Posts
    Select all code (works here):
    Code:
        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):
    Code:
        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;

  • #3
    Regular Coder
    Join Date
    Jul 2007
    Location
    Velsen Noord, Netherlands
    Posts
    206
    Thanks
    6
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by TheWolf1 View Post
    Select all code (works here):
    Code:
        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):
    Code:
        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.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •