Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

ListBox --> ComboBox 1

Status
Not open for further replies.

PaidtheUmpire

Programmer
Jan 4, 2004
105
AU
Is there a way to get the values selected in the ListBox to be placed in another ComboBox?

ie...
ComboBox 1 --> Select Team
ListBox -----> Select Players
ComboBox 2 --> Select Captain from Players Selected to Play
Delphi I can't get enough of you.


Delphi I can't get enough of you.
 
It seems to me that combobox2 will take values from table3 which has info about players with 1 named as captain.
We could use
select captain from players
where team = 'Liverpool'

as a query.
This query would then be added to the listbox by creating a query3captain variable. right click query3 and select field editor. Right click in the box and chose add all fields.

Now you can programatically type
combobox2.items.add(query3Captain.text);
 
Ensure that the Multiselect property of the ListBox is set to True.

Write an event handler along the lines of this OnClick handler for a TButton:
Code:
procedure TForm1.Button1Click(Sender: TObject);
var
  s: integer;
begin
  ComboBox1.Clear;
  for s := 0 to ListBox1.Items.Count - 1 do
    if ListBox1.Selected[s] then
      ComboBox1.Items.Add ( ListBox1.Items[s] );
end;

Andrew
Hampshire, UK
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top