Jump to content
Linuxuser1234

How to add an item to ComboEdit2 after an item from Comboedit1 has been selected

Recommended Posts

Im trying make a procedure that when you select an item from ComboEdit1 (it will officially list items from a ftp site) but for a test im 

trying to list the same item from ComboEdit1 to ComboEdit2 

procedure TForm4.ComboEdit1Click(Sender: TObject);
begin         

end;

i have tried %s like ComboEdit2.Items.Add('%S'); but that doesnt work  

here is the list items for ComboEdit1 and i havent been able to find code examples 

TTUL	 	
TTPA	 	
TSTL	 	 
TSLC	 	 
TSJU	 	 
TSDF	 	 
TRDU	 	 
TPIT	 	 
TPHX	 	 
TPHL	 	 
TPBI	 	 
TORD	 	 
TOKC	 	 
TMSY	 	
TMSP	 	 
TMKE	 	 
TMIA	 	 
TMEM	 	 
TMDW	 	 
TMCO	 	 
TMCI	 	 
TLVE	 	 
TLAS	 	 
TJUA	 	 
TJFK	 	 
TIDS	 	 
TICH	 	 
TIAH	 	 
TIAD	 	 
THOU	 	 
TFLL	 	 
TEWR	 	 
TDTW	 	 
TDFW	 	 
TDEN	 	 
TDCA	 	 
TDAY	 	 
TDAL	 	 
TCVG	 	 
TCMH	 	 
TCLT	 	 
TBWI	 	 
TBOS	 	 
TBNA	 	 
TATL	 	 
TADW	 	 
ROP4	 	 
ROP3	 	 
RODN	 	 
RKSG	 	 
RKJK	 	 
PHWA
PHMO	 	 
PHKM	 	 
PHKI	 	 
PGUA	 	 
PAPD	 	 
PAKC	 	 
PAIH	 	 
PAHG	 	 
PAEC	 	 
PACG	 	 
PABC	 	 
NOP4	 	 
NOP3	 	 
KYUX	 	 
KVWX	 	 
KVTX	 	 
KVNX	 	 
KVBX	 	 
KVAX	 	 
KUEX	 	 
KUDX	 	 
KTYX	 	 
KTWX	 	 
KTLX	 	 
KTLH	 	 
KTFX	 	 
KTBW	 	 
KSRX	 	 
KSOX	 	 
KSJT	 	 
KSHV	 	 
KSGF	 	 
KSFX	 	 
KRTX	 	 
KRLX	 	 
KRIW	 	
KRGX	 	 
KRAX	 	 
KPUX	 	 
KP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
DAN1

 

Edited by Linuxuser1234

Share this post


Link to post

Do you want to add the selected from ComboEdit1 to the dropdown of ComboEdit2?

 

Hook Combo1Edit.OnSelect

procedure TForm4.ComboEdit1OnSelect(Sender: TObject);
begin         
  ComboEdit2.Items.Add(ComboEdit1.Text);
end;

This event is called when an item is selected from the dropped down list of ComboEdit1.
Naturally, you need to add code to see if the item has already been added before you add it.

Share this post


Link to post

Do you want to add the selected from ComboEdit1 to the dropdown of ComboEdit2?

 

Hook Combo1Edit.OnSelect

procedure TForm4.ComboEdit1OnSelect(Sender: TObject);
begin         
  ComboEdit2.Items.Add(ComboEdit1.Text);
end;

This event is called when an item is selected from the dropped down list of ComboEdit1.
Naturally, you need to add code to see if the item has already been added before you add it.

@Lars Fosdal that doesnt work

Edited by Linuxuser1234

Share this post


Link to post

Sure what:

procedure TForm1.ComboEdit1Change(Sender: TObject);
var
  i: integer;
begin
  i := ComboEdit2.Items.IndexOf(ComboEdit1.Items[ComboEdit1.ItemIndex]);
  if i = -1 then
    begin
      ComboEdit2.Items.Add(ComboEdit1.Items[ComboEdit1.ItemIndex]);
      ComboEdit2.ItemIndex := ComboEdit2.Count - 1;
    end
  else
      ComboEdit2.ItemIndex := i;
end;


//---
procedure TForm1.ComboBox1Click(Sender: TObject);
 if (ComboBox2.Items.IndexOf(ComboBox1.Items[ComboBox1.ItemIndex]) = -1) then
 begin
    ComboBox2.Items.Add(ComboBox1.Items[ComboBox1.ItemIndex]);
    ComboBox2.ItemIndex := ComboBox2.GetCount-1
 end;
//

procedure TForm1.ListBox1Click(Sender: TObject);
begin
  if (ListBox2.Items.IndexOf(ListBox1.Items[ListBox1.ItemIndex]) = -1) then
    ListBox2.Items.Add(ListBox1.Items[ListBox1.ItemIndex]);
end;

 

Edited by programmerdelphi2k

Share this post


Link to post
36 minutes ago, Linuxuser1234 said:

TComboEdit does not contain GetCound and yes i have tried var

TComboBox is VCL and use "GetCount" or you can use "ComboBox1.Items.Count"

TComboEdit is FMX  (your project is FMX then... ) and use "Count" or "ComboEdit1.Items.Count"

 

NOTE: ComboEdit ONCLICK = click on component (into edit control from it), not on "Items"

Edited by programmerdelphi2k

Share this post


Link to post

that way it's better:

procedure TForm1.ComboEdit1Change(Sender: TObject);
var
  i: integer;
begin
  i := ComboEdit2.Items.IndexOf(ComboEdit1.Items[ComboEdit1.ItemIndex]);
  if i = -1 then
    i := ComboEdit2.Items.Add(ComboEdit1.Items[ComboEdit1.ItemIndex]);
  //
  ComboEdit2.ItemIndex := i;
end;

 

Edited by programmerdelphi2k
  • Like 1

Share this post


Link to post

Well, I should also pay better attention to details.  My initial reply was VCL code, not an FMX code.

My apologies.

 

TComboEdit.OnChange handler

procedure TForm2.ComboEdit1Change(Sender: TObject);
begin
  if ComboEdit2.Items.IndexOf(ComboEdit1.Text) < 0
   then ComboEdit2.Items.Add(ComboEdit1.Text);

  ComboEdit2.ItemIndex := ComboEdit2.Items.IndexOf(ComboEdit1.Text);
end;

 

 

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×