By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,678 Members | 2,402 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,678 IT Pros & Developers. It's quick & easy.

Displaying Arraylist to ListBox

P: n/a
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
Share this Question
Share on Google+
2 Replies


P: n/a
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

P: n/a
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 discussion thread is closed

Replies have been disabled for this discussion.