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
Вопрос
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).
Решение
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
Другие советы
Use GetItemText
and SelectedItem:
string foo = lbxcombo.GetItemText(lbxcombo.SelectedItem);
Or use the Text property:
string foo = lbxcombo.Text;
You can use:
String country = lbxcombo.SelectedItem.Text;
OR
Items[lbxcombo.SelectedIndex].Text
I'm pretty sure that you only need to use the text property for this :-
string Foo = lbxcombo.text;