如何通过传递其索引值从组合框中获取值 [英] how to get value from a combobox by passing its index value

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

问题描述

朋友们,

我希望在传递其索引值时从组合框中获取价值。例如:

假设以下是组合框中的值



Jan

2月

mar

apr

可能



如果我将2作为指数值传递,我想要想要mar作为结果我怎么能这样做请尽快帮助我

hi friends,
I want to get value from combobox when I pass its index value. for ex:
suppose the following are the value in combobox

Jan
Feb
mar
apr
may

I want if I pass "2" as index value and want "mar" as result how can i do it please help me soon

推荐答案

ComboBox 有一个属性名为 Items 这是一个集合,你可以使用 Index 访问每个项目。



例如:

ComboBox has has a property named Items that is a collection and you can access to each item with using Index.

For example:
MessageBox.Show(MyCombo.Items[2].ToString());







你可以用这个方法:






You can use this method too:

public object GetComboBoxItem(int index)
{
    if (index >= MyCombo.Items.Count)
        return null;

    return MyCombo.Items[index];
}


大家好,



非常简单你可以得到文字组合框用于一行中的特定索引





myCombobox.GetItemText(myCombobox.Items [index]);







谢谢

:)
Hi all,

Its very simple u can get the text of combobox for specific index in one line


myCombobox.GetItemText(myCombobox.Items[index]);



thanks
:)


你可以只需使用SelectedIndex选择它。查看链接以获取更多信息: http://msdn.microsoft。 com / en-us / library / system.windows.forms.combobox.selectedindex.aspx [ ^ ]



祝你好运!
You can simply select it using SelectedIndex. Check out the link for more info: http://msdn.microsoft.com/en-us/library/system.windows.forms.combobox.selectedindex.aspx[^]

Good luck!


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

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