473,466 Members | 1,332 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

MultiExtended & databound Listbox problem

Hello and thanks for your help,

I have the following Listbox created in VisualStudio 2003 designer, desiring
to select multiple entries from that list:
-------------------------------
ListBoxUser.Location = New System.Drawing.Point(16, 240)
ListBoxUser.Name = "ListBoxUser"
ListBoxUser.SelectionMode = System.Windows.Forms.SelectionMode.MultiExtended
ListBoxUser.Size = New System.Drawing.Size(136, 147)
ListBoxUser.TabIndex = 6
-------------------------------

Programatically I bind data with the following code:
-------------------------------
ListBoxUser.DataSource = objDS.Tables("tblUsers")
ListBoxUser.DisplayMember = "UserName"
ListBoxUser.ValueMember = "UserId"
-------------------------------

Later I loop through the selected items from ListBoxUser and verify these
selected items do not exist on DB. When I execute the code below
-------------------------------
For uIdx = 0 To ListBoxUser.SelectedItems.Count - 1

System.Diagnostics.Debug.WriteLine(ListBoxUser.Sel ectedItems(uIdx).ToString(
))
strUser = ListBoxUser.SelectedItems(uIdx).ToString()
Next For
-------------------------------
Debug.WriteLine shows value of 'System.Data.DataRowView' instead of 'Fred'
or 'Charlie'; and so does the contents of strUser (declared as string).

However, when creating the same kind of listbox programmatically without
databinding and the display works fine, eg. `Item 4` and index value of `1`
are displayed/printed:
-------------------------------
Dim listBox1 As New ListBox
' Set the size and location of the ListBox.
listBox1.Size = New System.Drawing.Size(200, 100)
listBox1.Location = New System.Drawing.Point(10, 10)
' Add the ListBox to the form.
Controls.Add(listBox1)
' Set the ListBox to display items in multiple columns.
listBox1.MultiColumn = False
' Set the selection mode to multiple and extended.
listBox1.SelectionMode = SelectionMode.MultiExtended
' Shutdown the painting of the ListBox as items are added.
listBox1.BeginUpdate()
' Loop through and add 50 items to the ListBox.
Dim x As Integer
For x = 1 To 50
listBox1.Items.Add("Item " & x.ToString())
Next x
' Allow the ListBox to repaint and display the new items.
listBox1.EndUpdate()
' Select three items from the ListBox.
listBox1.SetSelected(1, True)
listBox1.SetSelected(3, True)
listBox1.SetSelected(5, True)
' Display the second selected item in the ListBox to the console.
System.Diagnostics.Debug.WriteLine(listBox1.Select edItems(1).ToString())
' Display the index of the first selected item in the ListBox.
System.Diagnostics.Debug.WriteLine(listBox1.Select edIndices(0).ToString())
-------------------------------

So what am I doing wrong? How can I get the text/string values of the
selected items?

Many thanks for your help

Thomas
Nov 20 '05 #1
2 3809
Hi,

For x As Integer = 0 To ListBox1.Items.Count - 1
Dim dr As DataRowView = DirectCast(ListBox1.Items(x),
DataRowView)
Debug.WriteLine(dr("UserName").ToString)
Next

Ken
------------------------
"tangokilo" <tk******@ozemail.com.au> wrote in message
news:bR**************@nnrp1.ozemail.com.au...
Hello and thanks for your help,

I have the following Listbox created in VisualStudio 2003 designer,
desiring
to select multiple entries from that list:
-------------------------------
ListBoxUser.Location = New System.Drawing.Point(16, 240)
ListBoxUser.Name = "ListBoxUser"
ListBoxUser.SelectionMode =
System.Windows.Forms.SelectionMode.MultiExtended
ListBoxUser.Size = New System.Drawing.Size(136, 147)
ListBoxUser.TabIndex = 6
-------------------------------

Programatically I bind data with the following code:
-------------------------------
ListBoxUser.DataSource = objDS.Tables("tblUsers")
ListBoxUser.DisplayMember = "UserName"
ListBoxUser.ValueMember = "UserId"
-------------------------------

Later I loop through the selected items from ListBoxUser and verify these
selected items do not exist on DB. When I execute the code below
-------------------------------
For uIdx = 0 To ListBoxUser.SelectedItems.Count - 1

System.Diagnostics.Debug.WriteLine(ListBoxUser.Sel ectedItems(uIdx).ToString(
))
strUser = ListBoxUser.SelectedItems(uIdx).ToString()
Next For
-------------------------------
Debug.WriteLine shows value of 'System.Data.DataRowView' instead of 'Fred'
or 'Charlie'; and so does the contents of strUser (declared as string).

However, when creating the same kind of listbox programmatically without
databinding and the display works fine, eg. `Item 4` and index value of
`1`
are displayed/printed:
-------------------------------
Dim listBox1 As New ListBox
' Set the size and location of the ListBox.
listBox1.Size = New System.Drawing.Size(200, 100)
listBox1.Location = New System.Drawing.Point(10, 10)
' Add the ListBox to the form.
Controls.Add(listBox1)
' Set the ListBox to display items in multiple columns.
listBox1.MultiColumn = False
' Set the selection mode to multiple and extended.
listBox1.SelectionMode = SelectionMode.MultiExtended
' Shutdown the painting of the ListBox as items are added.
listBox1.BeginUpdate()
' Loop through and add 50 items to the ListBox.
Dim x As Integer
For x = 1 To 50
listBox1.Items.Add("Item " & x.ToString())
Next x
' Allow the ListBox to repaint and display the new items.
listBox1.EndUpdate()
' Select three items from the ListBox.
listBox1.SetSelected(1, True)
listBox1.SetSelected(3, True)
listBox1.SetSelected(5, True)
' Display the second selected item in the ListBox to the console.
System.Diagnostics.Debug.WriteLine(listBox1.Select edItems(1).ToString())
' Display the index of the first selected item in the ListBox.
System.Diagnostics.Debug.WriteLine(listBox1.Select edIndices(0).ToString())
-------------------------------

So what am I doing wrong? How can I get the text/string values of the
selected items?

Many thanks for your help

Thomas

Nov 20 '05 #2
Hi Thomas,

Probably the cases of the datanames between quotes, they are case sensetive.

If not, ask again?

Cor
Nov 20 '05 #3

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

Similar topics

0
by: Ken Varn | last post by:
I have a strange problem with a databound listbox. It may be because of how I use it, but I am stumped by this behavior. Here is the scenario: I have a multiselect databound listbox that...
1
by: Brian Henry | last post by:
I am working on an data bound list that implements of course IList, IBindingList, IComparer, etc... your basic things your need for data binding type objects... the problem is i got it to work...
3
by: joe | last post by:
I actually have 2 questions: 1) Is databinding the fastest way to load a listbox from sqlserver? speed is crucial and I want to make sure i'm populating it the fastest way i can 2) Also,...
4
by: Bernie Yaeger | last post by:
I've been able to get a pair of listboxes to pass data from one to the other successfully, but only one selected item at a time. If I change the listbox mode of both the multiextended, it only...
2
by: Alien2_51 | last post by:
I have a ListBox control with the SelectionMode set to MultiExtended bound to an IList collection. The ListBox control is on a tab control, if I have multiple items selected in the list box when I...
0
by: **Developer** | last post by:
I have a ListBox with: SelectionMode = SelectionMode.MultiExtended If I use the Shift key to select multiple items In the MouseMove event I see a
0
by: **Developer** | last post by:
Has anyone found out how to do DragDrop from a ListBox with SelectionMode.MultiExtended I've been searching Google and see that it is an old problem. I know from past experience that it stems...
4
by: Joao | last post by:
Hi all, I have 2 listboxes with SelectionMode = MultiExtended and I just cannot figure out why I get the error below: System.IndexOutOfRangeException was unhandled Message="Index was outside...
6
by: =?Utf-8?B?SnVzdGlu?= | last post by:
Hello: Does anyone know how I can create a multi-column listbox in VB.Net (Windows)...I am using VS.Net 2003. If there is another control available that can be databound with multiple...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
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,...
0
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...
0
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,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
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 ...

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.