ListBox(多扩展选择模式) [英] ListBox (Multi-Extended Selection Mode)
问题描述
我正在尝试将
me.NamesListBox.SelectedItems属性的内容显示在
表单上的标签上。这在单选模式下工作正常,但
当我试图调用多个项目时,我的语法显然有问题。我的代码中的行
给我预编译错误
类型''system.windows.form.textbox的值被选中
对象集合无法转换为字符串
///
Me.ResultLabel.Text = Me.NamesListBox.SelectedItems < br $>
///
任何想法家伙,提前谢谢
史蒂夫
///
Private Sub ExitButton_Click(ByVal sender As Object,
ByVal e As System.EventArgs)_
处理ExitButton.Click
Me.Close()
End Sub
Private Sub MultiForm_Load(ByVal发件人作为对象,
ByVal e As System.EventArgs)_
处理MyBase.Load
Me.NamesListBox.Items.Add(" Ahmad")
Me.NamesListBox.Items.Add(" Jim")
Me.NamesListBox.Items.Add(" Debbie")
Me.NamesListBox.Items.Add(" Jeanne")
Me.Nam esListBox.Items.Add(" Bill")
End Sub
Private Sub SingleButton_Click(ByVal sender As
Object, ByVal e As System.EventArgs)_
处理SingleButton.Click
Me.ResultLabel.Text = Me.NamesListBox.SelectedItem
>
End Sub
Private Sub MultiButton_Click(ByVal sender As Object,
ByVal e As System.EventArgs)_
处理MultiButton.Click
Me.ResultLabel.Text =""
Me.ResultLabel.Text =
Me.NamesListBox.SelectedItems
///
首先,你得到的错误是因为你没有指定.ToString()
结尾。
其次,这不会显示任何有意义的,只需
windows.forms.listbox.selecteditemscollection等
如果要显示连接的所有值的消息框。 SubClass
this并覆盖toString()函数并返回集合中所有
项的字符串。
; -D
HTH
-
问候 - 一名男子
作者:Fish .NET&保持.NET
======================================= ==
此帖子按原样提供。没有保证,
并且不授予任何权利。
Steven Smith <圣********** @ emailaccount.com>在消息中写道
news:1c **************************** @ phx.gbl ... < blockquote class =post_quotes>我正在尝试将
me.NamesListBox.SelectedItems属性的内容显示在
表单上的标签上。这在单选模式下工作正常,但
在尝试调用多个项目时,我的语法显然有问题。在我的代码下面的行
给我预编译错误的类型''system.windows.form.textbox的值选择
对象集合不能是转换为字符串
///
Me.ResultLabel.Text = Me.NamesListBox.SelectedItems
///
任何想法的家伙,谢谢提前
Steve
///
私人子ExitButton_Click(ByVal发件人为对象,
ByVal e As System .EventArgs)_
处理ExitButton.Click
Me.Close()
End Sub
私有Sub MultiForm_Load(ByVal发送者为对象,
ByVal e作为System.EventArgs)_
处理MyBase.Load
Me.NamesListBox.Items.Add(" Ahmad")
Me.NamesListBox.Items.Add(" Jim")
Me.NamesListBox.Items.Add(" Debbie")
Me.NamesListBox.Items.Add(" Jeanne")
Me.NamesListBox.Items.Add(" Bill")<结束S ub
Private Sub SingleButton_Click(ByVal sender As
Object,ByVal e As System.EventArgs)_
处理SingleButton.Click
Me.ResultLabel。 Text = Me.NamesListBox.SelectedItem
End Sub
私有子MultiButton_Click(ByVal发送者为对象,
ByVal e As System.EventArgs)_
处理MultiButton.Click
Me.ResultLabel.Text =""
Me.ResultLabel.Text =
Me.NamesListBox.SelectedItems
/ //
你好Steve,///
Me.ResultLabel.Text = Me.NamesListBox.SelectedItems
///
我不知道我给出的选项是否是最好的但我认为你
可以继续用它。
\\\\
Dim i As Integer
Me.ResultLabel.Text = Nothing
For i = 0 To NamesListBox.SelectedItems.Count - 1
Me.ResultLabel.Text = Me.ResultLabel.Text&
NamesListBox.SelectedItems(i).ToString& vbCrLf
下一页
////
成功
Cor
感谢Cor完美运作,我认为这就是一个人b / b $ Hany Man试图解释我要去研究它
直到找出它是如何工作的,再次感谢
你们两个人的帮助,保持良好的工作
问候,史蒂夫
I''m trying to display the contents of the
me.NamesListBox.SelectedItems property to a label on the
form. This works fine in single selection mode but
there''s obviously something wrong with my syntax when
trying to call multiple items. the line in my code below
gives me the pre-compiler error along the lines of
value of type ''system.windows.form.textbox selected
object collection cannot be converted to string
///
Me.ResultLabel.Text = Me.NamesListBox.SelectedItems
///
any ideas guys, thanks in advance
Steve
///
Private Sub ExitButton_Click(ByVal sender As Object,
ByVal e As System.EventArgs) _
Handles ExitButton.Click
Me.Close()
End Sub
Private Sub MultiForm_Load(ByVal sender As Object,
ByVal e As System.EventArgs) _
Handles MyBase.Load
Me.NamesListBox.Items.Add("Ahmad")
Me.NamesListBox.Items.Add("Jim")
Me.NamesListBox.Items.Add("Debbie")
Me.NamesListBox.Items.Add("Jeanne")
Me.NamesListBox.Items.Add("Bill")
End Sub
Private Sub SingleButton_Click(ByVal sender As
Object, ByVal e As System.EventArgs) _
Handles SingleButton.Click
Me.ResultLabel.Text = Me.NamesListBox.SelectedItem
End Sub
Private Sub MultiButton_Click(ByVal sender As Object,
ByVal e As System.EventArgs) _
Handles MultiButton.Click
Me.ResultLabel.Text = ""
Me.ResultLabel.Text =
Me.NamesListBox.SelectedItems
///
Firstly, you are getting the error because you did not specify .ToString()
on the end.
Secondly, this will not display anyting meaningfull, simply the
windows.forms.listbox.selecteditemscollection etc
If you want to display a messagebox of all the values concatenated. SubClass
this and override the toString() function and return the strings of all the
items in the collection.
;-D
HTH
--
Regards - One Handed Man
Author : Fish .NET & Keep .NET
=========================================
This posting is provided "AS IS" with no warranties,
and confers no rights.
"Steven Smith" <St**********@emailaccount.com> wrote in message
news:1c****************************@phx.gbl...I''m trying to display the contents of the
me.NamesListBox.SelectedItems property to a label on the
form. This works fine in single selection mode but
there''s obviously something wrong with my syntax when
trying to call multiple items. the line in my code below
gives me the pre-compiler error along the lines of
value of type ''system.windows.form.textbox selected
object collection cannot be converted to string
///
Me.ResultLabel.Text = Me.NamesListBox.SelectedItems
///
any ideas guys, thanks in advance
Steve
///
Private Sub ExitButton_Click(ByVal sender As Object,
ByVal e As System.EventArgs) _
Handles ExitButton.Click
Me.Close()
End Sub
Private Sub MultiForm_Load(ByVal sender As Object,
ByVal e As System.EventArgs) _
Handles MyBase.Load
Me.NamesListBox.Items.Add("Ahmad")
Me.NamesListBox.Items.Add("Jim")
Me.NamesListBox.Items.Add("Debbie")
Me.NamesListBox.Items.Add("Jeanne")
Me.NamesListBox.Items.Add("Bill")
End Sub
Private Sub SingleButton_Click(ByVal sender As
Object, ByVal e As System.EventArgs) _
Handles SingleButton.Click
Me.ResultLabel.Text = Me.NamesListBox.SelectedItem
End Sub
Private Sub MultiButton_Click(ByVal sender As Object,
ByVal e As System.EventArgs) _
Handles MultiButton.Click
Me.ResultLabel.Text = ""
Me.ResultLabel.Text =
Me.NamesListBox.SelectedItems
///
Hi Steve,///
Me.ResultLabel.Text = Me.NamesListBox.SelectedItems
///
I d''nt know if the Option I give beneath is Strict the best but I think you
can go On with it.
\\\\
Dim i As Integer
Me.ResultLabel.Text = Nothing
For i = 0 To NamesListBox.SelectedItems.Count - 1
Me.ResultLabel.Text = Me.ResultLabel.Text &
NamesListBox.SelectedItems(i).ToString & vbCrLf
Next
////
Success
Cor
Thanks Cor that worked perfectly, I think thats what One
Handed Man was trying to explain I''m gonna go study it
through to find out how it works exactly, thanks again to
both of you for your help, keep up the good work
Regards, Steve
这篇关于ListBox(多扩展选择模式)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!