帮我从Combobox获取文本。 [英] Help me to get text from Combobox.
本文介绍了帮我从Combobox获取文本。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
嗨朋友,
如果我使用以下代码,那么我会收到错误(附加信息:InvalidArgument ='2'的值对'index'无效。 )
Dim index1 As 整数 = 0
Dim 电子邮件< span class =code-keyword> 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
在你的函数之外并公开你的变量然后使用它
如果你使用一个计时器,那么<code> 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 = 0
Dim email As String = ComboBox1.Items.Item(index1).ToString
index1 = index1 + 1
But If I manually put index like 0 or something else then it works. Like following code works
Dim email As String = ComboBox1.Items.Item(0).ToString
Please 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).text
Use this
Dim index1 As Integer = 0
outside of your function and make your variable public and then use it
If you use a timer, thenindex1
becomes probably higher than the highest index ofItems
. 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 + 1 Else ' index1 is higher than the highest index of the combobox items End If
这篇关于帮我从Combobox获取文本。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文