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;
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top