473,769 Members | 6,160 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

ListBox (Multi-Extended Selection Mode)

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_Clic k(ByVal sender As Object,
ByVal e As System.EventArg s) _
Handles ExitButton.Clic k
Me.Close()
End Sub

Private Sub MultiForm_Load( ByVal sender As Object,
ByVal e As System.EventArg s) _
Handles MyBase.Load
Me.NamesListBox .Items.Add("Ahm ad")
Me.NamesListBox .Items.Add("Jim ")
Me.NamesListBox .Items.Add("Deb bie")
Me.NamesListBox .Items.Add("Jea nne")
Me.NamesListBox .Items.Add("Bil l")
End Sub

Private Sub SingleButton_Cl ick(ByVal sender As
Object, ByVal e As System.EventArg s) _
Handles SingleButton.Cl ick

Me.ResultLabel. Text = Me.NamesListBox .SelectedItem

End Sub

Private Sub MultiButton_Cli ck(ByVal sender As Object,
ByVal e As System.EventArg s) _
Handles MultiButton.Cli ck

Me.ResultLabel. Text = ""
Me.ResultLabel. Text =
Me.NamesListBox .SelectedItems

///
Nov 20 '05 #1
10 10092
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.l istbox.selected itemscollection 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**********@e mailaccount.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_Clic k(ByVal sender As Object,
ByVal e As System.EventArg s) _
Handles ExitButton.Clic k
Me.Close()
End Sub

Private Sub MultiForm_Load( ByVal sender As Object,
ByVal e As System.EventArg s) _
Handles MyBase.Load
Me.NamesListBox .Items.Add("Ahm ad")
Me.NamesListBox .Items.Add("Jim ")
Me.NamesListBox .Items.Add("Deb bie")
Me.NamesListBox .Items.Add("Jea nne")
Me.NamesListBox .Items.Add("Bil l")
End Sub

Private Sub SingleButton_Cl ick(ByVal sender As
Object, ByVal e As System.EventArg s) _
Handles SingleButton.Cl ick

Me.ResultLabel. Text = Me.NamesListBox .SelectedItem

End Sub

Private Sub MultiButton_Cli ck(ByVal sender As Object,
ByVal e As System.EventArg s) _
Handles MultiButton.Cli ck

Me.ResultLabel. Text = ""
Me.ResultLabel. Text =
Me.NamesListBox .SelectedItems

///

Nov 20 '05 #2
Cor
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.Se lectedItems.Cou nt - 1
Me.ResultLabel. Text = Me.ResultLabel. Text &
NamesListBox.Se lectedItems(i). ToString & vbCrLf
Next
////
Success
Cor
Nov 20 '05 #3

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
Nov 20 '05 #4
Cor
OK Steve ,
No he was not this is another Option,
Nice that you did reply.
Cor
Nov 20 '05 #5
:-))
Nov 20 '05 #6
-----Original Message-----
:-)) -----Original Message-----
:-))


Thanks for in depth analysis of Tic-Tac-Toe, mucho
gracias! on closer examination the first solution I
posted never worked as my error checking at the time
disabled the labels after click to prevent player from
overwriting other players marker, this was a cunning plan
however re-enabling the labels on ClearBoard.Clic k might
have helped. This leads me to believe that the original
do while...loop served the same functionality as the
later for...next, but I realise that there is a
difference between the two. The next tutorial for me is
a hangman game which I'm sure will throw up plenty new
string manipulation problems for me to chew over, will
continue to work on style to maximise legibility of my
code, thanks again, bye for now...
Regards, Steve
Nov 20 '05 #7
"Steven Smith" <St**********@e mailaccount.com > schrieb:
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


\\\
Dim o As Object
Dim sb As System.Text.Str ingBuilder = New System.Text.Str ingBuilder()
For Each o In Me.ListBox1.Sel ectedItems

' Change this depending on the type of your objects.
sb.Append(Direc tCast(o, String))

sb.Append(" ")
Next o
MsgBox(sb.ToStr ing())
///

--
Herfried K. Wagner
MVP · VB Classic, VB.NET
http://www.mvps.org/dotnet
Nov 20 '05 #8
-----Original Message-----
"Steven Smith" <St**********@e mailaccount.com > schrieb: \\\
Dim o As Object
Dim sb As System.Text.Str ingBuilder = New System.Text.Str ingBuilder()For Each o In Me.ListBox1.Sel ectedItems

' Change this depending on the type of your objects.
sb.Append(Direc tCast(o, String))

sb.Append(" ")
Next o
MsgBox(sb.ToSt ring())
///

--
Herfried K. Wagner
MVP · VB Classic, VB.NET
http://www.mvps.org/dotnet
.
Hi Herfried thanks for your response, I think this

solution is slightly beyond my ability just now as
DirectCast isn't in my vb vocabulary yet, although it is
always helpful to see there's more than one way to skin a
cat :) I'll try and implement the code in another project
and I'll see how I get on.

Thanks & appreciation for your help

Regards Steve
Nov 20 '05 #9
-----Original Message-----
Firstly, you are getting the error because you did not specify .ToString()on the end.
If you want to display a messagebox of all the values concatenated. SubClassthis and override the toString() function and return the strings of all theitems in the collection.


///
Public Overrides Function toString() As String

Return text

End Function
///

now I see the light..!
Nov 20 '05 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
5829
by: Jørgen Hansen | last post by:
Hi I have a problem with a Listbox in Tkinter. When I tab through several widgets with the tab-key, the listbox looses its selection, even though it has been selected with .selection_set. The example below demonstrates this. Can anyone provide me with some help on this? Regards Jorgen
8
25456
by: Peter Bailey | last post by:
I have a form that allows the user to selct items from a listbox and combo box. how do I reset them ready for the next set of entries. I thought I would have a clear button. regards in advance. Peter
1
5933
by: Liz | last post by:
I have used a ListView with several columns and lines to display an array ListView1.Items.Clear(); ListView1.Items.Add(aClients.Id); ListView1.Items.Add(aClients.Id); ListView1.Items.SubItems.Add(aClients.Surname); ListView1.Items.SubItems.Add(aClients.Forename); ListView1.Items.SubItems.Add(aClients.Surname);
0
1073
by: Stephen Adam | last post by:
Thgis one's got me stumped, have tried lots of methods to no avail. Here's what i'm trying to do. protected System.Web.UI.WebControls.ListBox lstFirstLevel; lstFirstLevel.SelectionMode = ListSelectionMode.Single; Does anyone know how to do this? Thanks
5
2316
by: Dave H | last post by:
I have an asp:listbox, allowing multiple selections, is there a quick check to see if there's more than one selected, or do I need to go through the whole list? Thanks, Dave
0
1774
by: Robin Tucker | last post by:
Hi there, I have a list box (just happens to be owner draw). When I select multiple items using the CTRL key, the items I have selected become highlighted (obviously). Now, when I click on one of the selected items in order to initiate a Drag operation, the other items are deselected and the item I have just clicked becomes the only one selected! I tested this with a normal list box (not owner draw) on a simple form. I can select...
2
1344
by: Bernie Yaeger | last post by:
I want to open a window with a listbox (custlist) in it, but I want to automatically select a certain item in the listbox, and have it be the correct selectedindex. The call to open this window knows what it seeks, which is variable. So one time I may wish to select item 45 (marsdon) and sometimes item 1997 (albert). How can I do this? Thanks for any help. Bernie Yaeger
1
1395
by: barbara_dave | last post by:
Hi, all, I know Listbox control has multiple and single mode for item selection. I need to use multiple selection mode, but I like to select items with shift or ctrl key and mouse. The reason is I like to select one item and unselect another one when I only use mouse. This function is just like window explorer's file selection. Could someone give me some instructions?
2
6706
by: sajones | last post by:
Hello, I'm a novice user having troubles retrieving data from a listbox in VB Express 2005. My listbox is populated by a table from an Access database. I'm trying to assign the current listbox selection to a textbox using: "Me.txtSelection.Text = CStr(lstUsers.Items(Me.lstUsers.SelectedIndex))"
0
10211
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10045
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9994
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9863
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8872
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5447
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3959
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3562
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2815
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.