How to get selected item from combo box to a variable

Posted on 2009-02-12
Last Modified: 2013-11-23
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.
Question by:IT79637
    LVL 36

    Accepted Solution

    var x: integer;
      t: string;
      x := Combobox1.ItemIndex;
      t := Combobox1.Text;
      // or :
      if Combobox1.ItemIndex > -1 then
        t := Combobox1.Items[Combobox1.ItemIndex];
    LVL 19

    Assisted Solution

    I don't know if you want the index of the value, so here's both:
    var index: integer;
        value: string;
     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)

    Open in new window

    LVL 19

    Expert Comment

    lol, too late :)
    LVL 36

    Expert Comment

    by:Geert Gruwez
    i didn't type that much comments ...
    LVL 1

    Author Closing Comment

    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.

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Better Security Awareness With Threat Intelligence

    See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

    Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
    Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
    This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
    THe viewer will learn how to use NetBeans IDE 8.0 for Windows to perform CRUD operations on a MySql database.

    737 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    19 Experts available now in Live!

    Get 1:1 Help Now