从列表框中项目上的文本获取列表框索引 [英] Get listbox index from the text on the item in the listbox
本文介绍了从列表框中项目上的文本获取列表框索引的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我的表单上有一个列表框,我需要能够从其文本中找到列表框上某个项目的索引.
例如.我有一个像这样的列表框
苹果
橙色
香蕉
大富克
我需要一种使用"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
,如下所示:
TheFindString
method ofListBox
control returns theindex
of string in the items of theListBox
as shown below:
int orangeIndex = listBox1.FindString("Orange");
int appleIndex = listBox1.FindString("Apple");
这篇关于从列表框中项目上的文本获取列表框索引的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文