473,387 Members | 1,515 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Displaying Arraylist to ListBox

I'm attempting to get an arraylist to display in a Listbox (listbox2). The
arraylist is created from selections in a different listbox (listbox1). The
1st listbox has a selection mode of MultiExtended. Once the selection has
been made in the 1st ListBox, the user clicks on a button to generate the
arraylist using the values selected. Then click a second button to display
the arraylist contents to ListBox2. There are no errors, but all I get in the
second ListBox is System.Data.DataRowView. I do not want to convert the
arraylist to a string as I want to eventually enter the values in the
arraylist in a database.

Here's the code that I have.

'This is in the form's load event, to populate the 1st ListBox
ListBox1.DataSource = DsPlayerStats1.tblPlayers
ListBox1.DisplayMember = "Expr1"
ListBox1.SelectionMode = SelectionMode.MultiExtended

'Now the code for the 1st button to add the selected items to the arraylist
Private Sub btnAddPlayer_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnAddPlayer.Click
TourneyField.AddRange(ListBox1.SelectedItems)
End Sub

'Now the code to display the contents of the arraylist in the 2nd ListBox.
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button2.Click

For Each pl In TourneyField
ListBox2.Items.Add(pl)
Next

TourneyField.Clear()
End Sub

Any suggestions, or help would be appreciated.

Cheers,
Steve


Jul 21 '05 #1
2 4185
Why do you manually add items to ListBox2? Why not databind it, like
ListBox2.DataSource = TourneyField. Keep in mind that you don't want to
TourneyField.Clear() anymore then. Just work on TourneyField's values
instead of manipulating the listbox. I find it also helpfull to check
how TourneyField looks like in memory, so you could try that aswell and
see if it is correct there. Also, try see if settings the DisplayMember
property helps.

Michel van den Berg

Fieldmedic wrote:
I'm attempting to get an arraylist to display in a Listbox (listbox2). The
arraylist is created from selections in a different listbox (listbox1). The
1st listbox has a selection mode of MultiExtended. Once the selection has
been made in the 1st ListBox, the user clicks on a button to generate the
arraylist using the values selected. Then click a second button to display
the arraylist contents to ListBox2. There are no errors, but all I get in the
second ListBox is System.Data.DataRowView. I do not want to convert the
arraylist to a string as I want to eventually enter the values in the
arraylist in a database.

Here's the code that I have.

'This is in the form's load event, to populate the 1st ListBox
ListBox1.DataSource = DsPlayerStats1.tblPlayers
ListBox1.DisplayMember = "Expr1"
ListBox1.SelectionMode = SelectionMode.MultiExtended

'Now the code for the 1st button to add the selected items to the arraylist
Private Sub btnAddPlayer_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnAddPlayer.Click
TourneyField.AddRange(ListBox1.SelectedItems)
End Sub

'Now the code to display the contents of the arraylist in the 2nd ListBox.
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button2.Click

For Each pl In TourneyField
ListBox2.Items.Add(pl)
Next

TourneyField.Clear()
End Sub

Any suggestions, or help would be appreciated.

Cheers,
Steve


Jul 21 '05 #2
I tired the ListBox2.DataSource = TourneyField and get the same stuff
displayed in the listbox (System.Data.DataRowView). As for the display member
portion, I'm at a loss since I'm dealing with an arraylist and not an actual
dataset. Any suggestions?

Regards,
Steve
"Michel van den Berg" wrote:
Why do you manually add items to ListBox2? Why not databind it, like
ListBox2.DataSource = TourneyField. Keep in mind that you don't want to
TourneyField.Clear() anymore then. Just work on TourneyField's values
instead of manipulating the listbox. I find it also helpfull to check
how TourneyField looks like in memory, so you could try that aswell and
see if it is correct there. Also, try see if settings the DisplayMember
property helps.

Michel van den Berg

Fieldmedic wrote:
I'm attempting to get an arraylist to display in a Listbox (listbox2). The
arraylist is created from selections in a different listbox (listbox1). The
1st listbox has a selection mode of MultiExtended. Once the selection has
been made in the 1st ListBox, the user clicks on a button to generate the
arraylist using the values selected. Then click a second button to display
the arraylist contents to ListBox2. There are no errors, but all I get in the
second ListBox is System.Data.DataRowView. I do not want to convert the
arraylist to a string as I want to eventually enter the values in the
arraylist in a database.

Here's the code that I have.

'This is in the form's load event, to populate the 1st ListBox
ListBox1.DataSource = DsPlayerStats1.tblPlayers
ListBox1.DisplayMember = "Expr1"
ListBox1.SelectionMode = SelectionMode.MultiExtended

'Now the code for the 1st button to add the selected items to the arraylist
Private Sub btnAddPlayer_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnAddPlayer.Click
TourneyField.AddRange(ListBox1.SelectedItems)
End Sub

'Now the code to display the contents of the arraylist in the 2nd ListBox.
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button2.Click

For Each pl In TourneyField
ListBox2.Items.Add(pl)
Next

TourneyField.Clear()
End Sub

Any suggestions, or help would be appreciated.

Cheers,
Steve


Jul 21 '05 #3

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

Similar topics

4
by: Jason | last post by:
Here is an odd issue. I am trying to shed some light on why this is causing a problem. I have an ArrayList. I am binding it to a ListBox control with has its Sort property set to True. If the...
0
by: Jesse Martinez | last post by:
My problem occurs when I use an ArrayList as a ListBox.DataSource. When the ArrayList attached to the Listbox is not empty the Listbox behave normal without problem, but if I remove all items...
4
by: Rhea Bockhorst | last post by:
I am just getting started in C#. What control do I use to display an array of double?
3
by: RBCC | last post by:
I have a form with a listbox and two textboxes. In the listbox I have the make and models of automobiles. and as the user clicks on the make of the car in the listbox I would like to output the make...
13
by: Larry Woods | last post by:
I am creating a "from-to" set of listboxes where the "left" listbox had a list of values and I want to be able to select these values, 1 at a time, and move them into a "right" listbox, removing...
0
by: Dave | last post by:
Hi all, I have a listbox that is complex bound by an arraylist. The problem is that when I delete an object from the arraylist, the listbox does not reflect those changes. I tried refreshing...
16
by: Allen | last post by:
I have a class that returns an arraylist. How do I fill a list box from what is returned? It returns customers which is a arraylist but I cant seem to get the stuff to fill a list box. I just...
5
by: John Veldthuis | last post by:
My code works perfectly 100% when adding items to my ArrayList and updating the listbox. Works perfectly when deleting an item in the ArrayList when it is not the last entry but if it is the last...
3
by: Fieldmedic | last post by:
I'm attempting to get an arraylist to display in a Listbox (listbox2). The arraylist is created from selections in a different listbox (listbox1). The 1st listbox has a selection mode of...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
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...

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.