如何仅从组合框 c# 中获取第一个索引 [英] How to take only first index from combobox c#
本文介绍了如何仅从组合框 c# 中获取第一个索引的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我的组合框上有两个索引.
I have two indexes on my combobox.
我只想取第一个索引?
我可以举一些例子吗?
代码:
foreach (DataRow dr2 in dt2.Rows)
{
comboBox1.Items.Add(dr2["Station"].ToString() + " - " + dr2["Ime"].ToString());
}
我想要dr2[Station"].ToString()
?
推荐答案
Win Forms ComboBox
具有 SelectedIndex
和 SelectedText
属性.
The Win Forms ComboBox
has both a SelectedIndex
and SelectedText
property.
一旦您的列表加载了项目,您就可以像这样选择哪一个:
Once your list is loaded with items you can pick which one is selected like this:
// selected by position in the list
comboBox1.SelectedIndex = 0;
// ... by value
comboBox1.SelectedText = "some value";
这篇关于如何仅从组合框 c# 中获取第一个索引的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文