10 Replies - 5058 Views - Last Post: 15 September 2013 - 12:59 PM Rate Topic: -----

#1 CodeMasterDeam   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 14-September 13

Copy Items From Listbox to Listbox

Posted 14 September 2013 - 11:12 PM

Hi,
I need your help in a little project I am doing the objective of the project is to copy items from 1 list box to another. list box 1 items into list box 2 items.

Posted Image

the code I currently have is as follows;

ListBox2.Items.Add(ListBox1.SelectedItems)


but as you can see in the sample picture I can only see the word (collection) in the list box.

what I am doing wrong and is this even possible.

Thanks for reading and any help you can offer.

Kind Regards

CodeMasterDream

This post has been edited by modi123_1: 15 September 2013 - 01:18 AM
Reason for edit:: fixed image


Is This A Good Question/Topic? 0
  • +

Replies To: Copy Items From Listbox to Listbox

#2 Atli   User is offline

  • Enhance Your Calm
  • member icon

Reputation: 4240
  • View blog
  • Posts: 7,216
  • Joined: 08-June 10

Re: Copy Items From Listbox to Listbox

Posted 15 September 2013 - 12:40 AM

This would be because the ListBox.SelectedItems Property returns a collection, as the name of the property suggests. (Plural names tend to do that.)

The property returns a SelectedObjectCollection instance, which you can use to go through the list of selected items and add them individually to your second list box.
Was This Post Helpful? 1
  • +
  • -

#3 CodeMasterDeam   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 14-September 13

Re: Copy Items From Listbox to Listbox

Posted 15 September 2013 - 01:15 AM

Thank you for your reply can you provide a sample of code suggestion that I could use

Kind Regards
Was This Post Helpful? 0
  • +
  • -

#4 modi123_1   User is online

  • Suitor #2
  • member icon



Reputation: 14237
  • View blog
  • Posts: 57,113
  • Joined: 12-June 08

Re: Copy Items From Listbox to Listbox

Posted 15 September 2013 - 01:20 AM

How about you try it before asking folks to do the work for you.
Was This Post Helpful? 0
  • +
  • -

#5 Michael26   User is offline

  • Futurama: Insert funny joke here
  • member icon

Reputation: 414
  • View blog
  • Posts: 1,664
  • Joined: 08-April 09

Re: Copy Items From Listbox to Listbox

Posted 15 September 2013 - 02:28 AM

OP, you need to loop through collection, do you know how loops work?
Was This Post Helpful? 1
  • +
  • -

#6 verisign33   User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 4
  • Joined: 13-July 13

Re: Copy Items From Listbox to Listbox

Posted 15 September 2013 - 06:10 AM

Copy the Listbox1 items to Listbox2 write the code like this on the form load even OR on a button click event where u want :-
Dim i As Integer = 0
        For i = 0 To ListBox1.Items.Count - 1
            If Not ListBox1.Items.Count = 0 Then
                ListBox2.Items.Add(ListBox1.Items.Item(i))
            End If
        Next


This post has been edited by andrewsw: 15 September 2013 - 07:04 AM
Reason for edit:: Removed unnecessary quote

Was This Post Helpful? 1
  • +
  • -

#7 andrewsw   User is offline

  • So Smart! S-M-R-T!
  • member icon

Reputation: 6578
  • View blog
  • Posts: 26,715
  • Joined: 12-December 12

Re: Copy Items From Listbox to Listbox

Posted 15 September 2013 - 07:08 AM

verisign33 your if-statement would be better placed outside of (before) the loop.
Was This Post Helpful? 0
  • +
  • -

#8 CodeMasterDeam   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 14-September 13

Re: Copy Items From Listbox to Listbox

Posted 15 September 2013 - 12:22 PM

View Postverisign33, on 15 September 2013 - 06:10 AM, said:

Copy the Listbox1 items to Listbox2 write the code like this on the form load even OR on a button click event where u want :-
Dim i As Integer = 0
        For i = 0 To ListBox1.Items.Count - 1
            If Not ListBox1.Items.Count = 0 Then
                ListBox2.Items.Add(ListBox1.Items.Item(i))
            End If
        Next



Thank you so much for all your help it was perfect works a treat this topic is resolved

View PostMichael26, on 15 September 2013 - 02:28 AM, said:

OP, you need to loop through collection, do you know how loops work?


Nope but would love to learn thanks for understanding my position

Thanks all for you help and to verisign33 for solving my problem.

Kind Regards
Was This Post Helpful? 0
  • +
  • -

#9 Michael26   User is offline

  • Futurama: Insert funny joke here
  • member icon

Reputation: 414
  • View blog
  • Posts: 1,664
  • Joined: 08-April 09

Re: Copy Items From Listbox to Listbox

Posted 15 September 2013 - 12:51 PM

Loops are like second thing you learn right after what variables are. This is really a beginners problem, and as beginner you should do the basics first the go for controls like listview later.
Programming fundamentals part 1
Programming fundamentals part 2
Was This Post Helpful? 1
  • +
  • -

#10 andrewsw   User is offline

  • So Smart! S-M-R-T!
  • member icon

Reputation: 6578
  • View blog
  • Posts: 26,715
  • Joined: 12-December 12

Re: Copy Items From Listbox to Listbox

Posted 15 September 2013 - 12:57 PM

View PostMichael26, on 15 September 2013 - 07:51 PM, said:

Loops are like second thing you learn right after what variables are. This is really a beginners problem, and as beginner you should do the basics first the go for controls like listview later.
Programming fundamentals part 1
Programming fundamentals part 2

Nice tutorials ;)
Was This Post Helpful? 0
  • +
  • -

#11 Michael26   User is offline

  • Futurama: Insert funny joke here
  • member icon

Reputation: 414
  • View blog
  • Posts: 1,664
  • Joined: 08-April 09

Re: Copy Items From Listbox to Listbox

Posted 15 September 2013 - 12:59 PM

Always ;)
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1