Search code examples
c#textindexinglistboxselectedindex

How to get text from a Selected Index c#


Once the country has been located by the search show the integer and the names of the two countries immediately before that country on the list. I know how to get the index value of the selected country, but i don't know how to get the text that it is highlighting.

e.g Australia has an index of 10. I can get the index value using:

int f = lbxcombo.SelectedIndex;

where f is the index value. But I can't get the text that the index represents (Australia).


Solution

  • lbxcombo.Items[index] will return the text at the index

    in your case use

    int f = lbxcombo.SelectedIndex;
    
    string text=lbxcombo.Items[f].ToString()
    

    to get australia