• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 21235
  • Last Modified:

How to get selected item from combo box to a variable

Hi Experts.

How do I get the selected value out of a combo box and into a variable?  I puzzled, because I don't know what the index is.
var := ComboBox1.???;

Thanks much.
0
IT79637
Asked:
IT79637
  • 2
  • 2
2 Solutions
 
Geert GruwezOracle dbaCommented:
var x: integer;
  t: string;
begin
  x := Combobox1.ItemIndex;
  t := Combobox1.Text;
 
  // or :
  if Combobox1.ItemIndex > -1 then
    t := Combobox1.Items[Combobox1.ItemIndex];
end;
0
 
MerijnBSr. Software EngineerCommented:
I don't know if you want the index of the value, so here's both:
var index: integer;
    value: string;
begin
 index := ComboBox1.ItemIndex;
 value := ComboBox1.Items[ComboBox1.ItemIndex];
 // you might want to check if the index is valid (it can be -1 if nothing is selected)
end;

Open in new window

0
 
MerijnBSr. Software EngineerCommented:
lol, too late :)
0
 
Geert GruwezOracle dbaCommented:
i didn't type that much comments ...
0
 
IT79637Author Commented:
Thanks for your response.  I upped the points to 400 points so points could be awarded to both Geert_Gruwez and MerijnB. Their responses were correct and the fact they responded within a minute of each other.

Thanks again.
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now