Combobox text in richedit at specified line

When I select an item in a combobox, I want the item add in a richedit at a specified line.

The line in the richedit should be something like:
"Employee: (name from combobox)"

How can I do this, any help would be great.
LVL 1
delphibeginnerAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Emmanuel PASQUIERFreelance Project ManagerCommented:
RichEdit.Lines.Insert(LineNumber,'Employee:'+combobox.Text);
sYk0Commented:
epasquier answer is correct, however if you want to modify a specific line (not append) use the following code.
procedure TForm1.ComboBox1Change(Sender: TObject);
begin
  with RichEdit1 do
  begin
    // Change the number to suite the line you would like to modify.
    Lines.Strings[1] := Format('Employee: %s', [ComboBox1.Text])
  end;
end;

Open in new window

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
delphibeginnerAuthor Commented:
Thanks, sYk0, that works like it should be, the only question with this is:

When I first select an employee, then when I select nothing in the combobox (the top of the combobox), the row should be removed.

Thanks.
Learn Ruby Fundamentals

This course will introduce you to Ruby, as well as teach you about classes, methods, variables, data structures, loops, enumerable methods, and finishing touches.

sYk0Commented:
I'm not sure what you are trying to achieve, deleting a line may cause information to get overridden (if there's something below the line you just deleted).

i have written a small procedure (see below), hopefully this will help...
procedure ModifyEmployee(RichEdit: TRichEdit; LineNumber: Integer; ComboBox: TComboBox; InsertLine: Boolean = False);
begin
  with RichEdit do
  begin
    case ComboBox.ItemIndex of
      0: Lines.Delete(LineNumber);
      else
      begin
        if InsertLine then
          Lines.Insert(LineNumber, Format('Employee: %s', [ComboBox.Text]))
        else
          Lines.Strings[LineNumber] := Format('Employee: %s', [ComboBox.Text]);
      end;
    end;
  end;
end;

// use it like this...
procedure TForm1.ComboBox1Change(Sender: TObject);
begin
  ModifyEmployee(RichEdit1, 1, ComboBox1);
end;

Open in new window

systanCommented:
RichEdit1.Lines.add(combobox1.Items.Strings[combobox1.Itemindex]);
systanCommented:
procedure TForm1.ComboBox1Click(Sender: TObject);
begin
RichEdit1.Lines.add(combobox1.Items.Strings[combobox1.Itemindex]);
end;
delphibeginnerAuthor Commented:
This works perfect.
systanCommented:
Hmp

procedure TForm1.ComboBox1Click(Sender: TObject);
begin
RichEdit1.Lines.add(combobox1.Items.Strings[combobox1.Itemindex]);
end;


Just add during startup :
ComboBox1.style:=csDropDownList;
ComboBox1.ItemIndex:=0;



No problem...
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Editors IDEs

From novice to tech pro — start learning today.