从列表框中项目上的文本获取列表框索引

从列表框中项目上的文本获取列表框索引

问题描述:

我的表单上有一个列表框,我需要能够从其文本中找到列表框上某个项目的索引.

例如.我有一个像这样的列表框

苹果
橙色
香蕉
大富克


我需要一种使用"Orange"或"Apple"来获取索引的方法,因此它将返回1或0

有办法吗?

ty

I have a list box on my form and I need to be able to find out the Index of an item on the listbox from it''s text.

E.G. I had a listbox like this

Apple
Orange
Banana
Dafuq


I need a way to get the index by using "Orange" or "Apple" so it would return 1 or 0

Is there a way to do this?

ty

ListBox 控件的FindString 方法返回index 项中字符串的index ,如下所示:
The FindString method of ListBox control returns the index of string in the items of the ListBox as shown below:
int orangeIndex = listBox1.FindString("Orange");
int appleIndex = listBox1.FindString("Apple");