Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/ms-access/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 按索引ID检索DropDownList的值_C#_Drop Down Menu - Fatal编程技术网

C# 按索引ID检索DropDownList的值

C# 按索引ID检索DropDownList的值,c#,drop-down-menu,C#,Drop Down Menu,我试图通过指定下拉列表的indexid来检索下拉列表的值,但我似乎找不到实现这一点的方法。我也不希望它是选中的值,基本上我需要遍历列表,然后将其添加到数组中。我可以找到各种各样的方法来获得它的基础上的值,但不是由索引id有人知道如何做到这一点?我正在使用c#.字符串值index=myComboBox.Items[myComboBox.SelectedIndex].ToString() String valueAtIndex=myComboBox.Items[myComboBox.Selected

我试图通过指定下拉列表的indexid来检索下拉列表的值,但我似乎找不到实现这一点的方法。我也不希望它是选中的值,基本上我需要遍历列表,然后将其添加到数组中。我可以找到各种各样的方法来获得它的基础上的值,但不是由索引id有人知道如何做到这一点?我正在使用c#.

字符串值index=myComboBox.Items[myComboBox.SelectedIndex].ToString()

String valueAtIndex=myComboBox.Items[myComboBox.SelectedIndex].ToString()

您是否尝试过
lstnother.SelectedIndex


由于该对象支持
IEnumerable
,因此如果您想循环,可以使用
foreach
进行循环。

您是否尝试过
lstnother.SelectedIndex


由于该对象支持
IEnumerable
,因此如果您愿意,可以使用
foreach
进行循环

字符串值index=myComboBox.Items[SomeIndexValue].Value

这就是你要找的吗

 List<String> theList = new List<string>();
        foreach (var item in comboBox1.Items)
        {
            theList.Add(item.ToString());
        }
List theList=新列表();
foreach(comboBox1.Items中的变量项)
{
添加(item.ToString());
}
其中comboBox1是您的下拉列表,我假设您谈论的是一个windows窗体项目

或者,如果您想使用索引Id:

List<string> theList = new List<string>();
            for (int i = 0; i < comboBox1.Items.Count; i++)
            {
                theList.Add(comboBox1.Items[i].ToString());
            }
List theList=新列表();
对于(int i=0;i
这就是你要找的吗

 List<String> theList = new List<string>();
        foreach (var item in comboBox1.Items)
        {
            theList.Add(item.ToString());
        }
List theList=新列表();
foreach(comboBox1.Items中的变量项)
{
添加(item.ToString());
}
其中comboBox1是您的下拉列表,我假设您谈论的是一个windows窗体项目

或者,如果您想使用索引Id:

List<string> theList = new List<string>();
            for (int i = 0; i < comboBox1.Items.Count; i++)
            {
                theList.Add(comboBox1.Items[i].ToString());
            }
List theList=新列表();
对于(int i=0;i
或任何索引都可以放在括号内,括号应为
myComboBox.Items[myComboBox.SelectedIndex].Value.ToString()或任何索引都可以放在括号内,括号应为
myComboBox.Items[myComboBox.SelectedIndex].Value.ToString()