如何从组合框C#中的选定值中获取选定索引 [英] How to get selected index from selected value in combo box C#

查看:105
本文介绍了如何从组合框C#中的选定值中获取选定索引的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有任何内置方法可用于从ComboBox控件C#中的选定值获取选定索引。如果没有,我该如何构建自己的一个

Is there any built-in method for getting selected index from selected value in ComboBox control C#. If not, how can I built my own one

预先感谢

推荐答案

我认为您正在寻找SelectedIndex属性。

I think you're looking for the SelectedIndex property.

int index = comboref.SelectedIndex

在寻找特定值的索引而不是所选索引时,

As you're looking for the index of a specific value not the selected one you can do

int index = comboref.Items.IndexOf("string");

它会告诉您哪个索引在组合框上具有字符串

and it will tell you which Index has "string" on the combobox

这篇关于如何从组合框C#中的选定值中获取选定索引的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆