Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8987825
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T21:53:00+00:00 2026-06-15T21:53:00+00:00

I am working on Delphi 7. I have one TListBox and one TStringGrid with

  • 0

I am working on Delphi 7. I have one TListBox and one TStringGrid with two columns (with no fixed row or column). I have data in the TListBox as follows:

Available Elements – a123 (a123)
Available Elements – a1234 (a1234)
Available Elements – a12345 (a12345)

And the TStringGrid is having following data as follows:

Column1 Column2

a1 Available Elements – a1
a2 Available Elements – a12

If I select the first item in the TListbox i.e. a123 and execute following button click event procedure, then the last item data ie a12345 is getting moved into the grid.

Could anybody put the focus on what I am doing wrong in the following code. Following code moves the seleted item in the TListbox to TStringgird’s two columns:

procedure TForm1.btnMoveLeftClick(Sender: TObject);
var
  sString : String;
  i : Integer;
begin
  for i := 0 to ListBox1.Items.Count - 1 do
  begin
      {-- Is this status selected? --}
      if ListBox1.Selected[i] then
      begin
        sString := Trim(ListBox1.Items[i]);

        {-- Delete selected status. --}
          ListBox1.Items.Delete (i);

        if ((grdVFormDetails.RowCount >= 1) And (Trim(grdVFormDetails.Cells[0, 0]) <> EmptyStr)) then
          grdVFormDetails.RowCount := grdVFormDetails.RowCount+1;

        grdVFormDetails.Cols[1].Add(Copy(sString, 1, Pos('(', sString) - 1));

        sString := Copy(sString, Pos('(', sString) + 1, Length(sString));
        sString := Copy(sString, Pos('(', sString) + 1, Length(sString) - 1);

        grdVFormDetails.Cols[0].Add(sString);


        break;
      end;
  end;
end;
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T21:53:01+00:00Added an answer on June 15, 2026 at 9:53 pm

    Assuming, you want to parse the input string like this:

    'Some text (comment) etc. (12345)'
    

    into a part with a trimmed string from the beginning to the first opening parenthesis (first from the end) of the input string to get a value like this:

    'Some text (comment) etc.'
    

    and the string from inside the last parentheses of the input string:

    '12345'
    

    If so, you can use the code that follows. Note that is expected to have list box items terminated by closing parentheses. You may check the commented version of this code or download a sample project if you want.

    Here is the part, which moves the focused item from the list box to the string grid:

    procedure TForm1.MoveLeftButtonClick(Sender: TObject);
    var
      S: string;
      I: Integer;
      ItemID: string;
      ItemText: string;
    begin
      if ListBox1.ItemIndex = -1 then
        Exit;
    
      S := ListBox1.Items[ListBox1.ItemIndex];
      for I := Length(S) - 1 downto 1 do
      begin
        if S[I] = '(' then
        begin
          ItemID := Trim(Copy(S, I + 1, Length(S) - I - 1));
          ItemText := Trim(Copy(S, 1, I - 1));
          with StringGrid1 do
          begin
            if (Cells[0, RowCount - 1] <> '') and
              (Cells[1, RowCount - 1] <> '')
            then
              RowCount := RowCount + 1;
            Cells[0, RowCount - 1] := ItemID;
            Cells[1, RowCount - 1] := ItemText;
          end;
          ListBox1.Items.Delete(ListBox1.ItemIndex);
          Break;
        end;
      end;
    end;
    

    And here is the part which moves the selected row from the string grid to the list box:

    procedure TForm1.MoveRightButtonClick(Sender: TObject);
    var
      I: Integer;
      RowIndex: Integer;
    begin
      RowIndex := StringGrid1.Selection.Top;
      if (StringGrid1.Cells[0, RowIndex] <> '') and
        (StringGrid1.Cells[1, RowIndex] <> '') then
      begin
        ListBox1.Items.Add(
          Trim(StringGrid1.Cells[1, RowIndex]) + ' (' +
          Trim(StringGrid1.Cells[0, RowIndex]) + ')'
        );
        for I := RowIndex to StringGrid1.RowCount - 2 do
          StringGrid1.Rows[I].Assign(StringGrid1.Rows[I + 1]);
        if StringGrid1.RowCount > 1 then
          StringGrid1.RowCount := StringGrid1.RowCount - 1
        else
        begin
          StringGrid1.Cells[0, 0] := '';
          StringGrid1.Cells[1, 0] := '';
        end;
      end;
    end;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am working with delphi. I have one scroll box in which I am
I have some Delphi 2007 code which runs in two different applications, one is
I have two string lists that I'm working with. One that has a list
hey im working on delphi 7, and i have a scenario for a available
I have a simple Delphi program that I'm working on, in which I am
i am working on a custom component in Delphi -7 for which i have
I am working with delphi. I have TImage, to which I assign a bitmap.
I have a multi-threaded Delphi 6 Pro application that I am currently working on
I'm working with Windows API and have to recreate a structure inside a Delphi
I'm working in Borland Delphi, and i have a few lines code in Borland

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.