本文介绍了帮我从Combobox获取文本。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 嗨朋友, 如果我使用以下代码,那么我会收到错误(附加信息:InvalidArgument ='2'的值对'index'无效。 ) Dim index1 As 整数 = 0 Dim 电子邮件 As String = ComboBox1.Items.Item(index1).ToString index1 = index1 + 1 但如果我手动输入索引像0或其他东西那么它的工作原理。如下代码作品 Dim email As String = ComboBox1.Items.Item( 0 )。ToString 请告诉我这是什么问题?解决方案 string s =((yourItemType)yourComboBox.SelectedItem).yourWishProperty;在C# 在这种情况下 Dim email As String =((string)ComboBox1.SelectedItem) .text 使用此 Dim index1 As 整数 = 0 在你的函数之外并公开你的变量然后使用它 如果你使用一个计时器,那么 index1 可能高于 Items 的最高索引。在您尝试从组合框中获取项目之前,请检查是否可能: 如果 ComboBox1.Items.Count> index1 然后 Dim 电子邮件 As 字符串 = ComboBox1.Items.Item(index1).ToString index1 = index1 + 1 否则 ' index1 is高于组合框项目的最高索引 结束 如果 Hi Friend,If I use following code then I get error (Additional information: InvalidArgument=Value of '2' is not valid for 'index'.)Dim index1 As Integer = 0Dim email As String = ComboBox1.Items.Item(index1).ToStringindex1 = index1 + 1But If I manually put index like 0 or something else then it works. Like following code worksDim email As String = ComboBox1.Items.Item(0).ToStringPlease tell me what's the problem is? 解决方案 string s = ((yourItemType)yourComboBox.SelectedItem).yourWishProperty; in C#In this case Dim email As String = ((string)ComboBox1.SelectedItem).textUse this Dim index1 As Integer = 0 outside of your function and make your variable public and then use itIf you use a timer, then index1 becomes probably higher than the highest index of Items. Before you try to get the item from the combobox, check whether it is possible:If ComboBox1.Items.Count > index1 Then Dim email As String = ComboBox1.Items.Item(index1).ToString index1 = index1 + 1Else ' index1 is higher than the highest index of the combobox itemsEnd If 这篇关于帮我从Combobox获取文本。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!
10-11 23:10