|
-
Dec 23rd, 2003, 09:59 AM
#1
Thread Starter
Fanatic Member
ListBox.AddRange
Hi all,
I want to move selected items from one ListBox to the other. Like
VB Code:
ListBox2.AddRange(ListBox1.Items)
will move all items from ListBox1 to ListBox2. Similarly, I want to move only selected (multiple selection) items from ListBox1 to ListBox2.
Well, I would like to mention that unfortunately
VB Code:
ListBox2.AddRange(ListBox1.SelectedItems)
is not working.
Pls guide.
Regards,
Prakash
-
Dec 23rd, 2003, 11:54 AM
#2
Junior Member
Whats the error that you are getting?
Instead of what you have, try using
VB Code:
ListBox2.AddRange(ListBox1.ObjectCollection)
and
VB Code:
ListBox2.AddRange(ListBox1.SelectedObjectCollection)
See if that fixes your problem
-
Dec 23rd, 2003, 05:09 PM
#3
New Member
check this...
Private Sub btnMove_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnMove.Click
Dim i As Integer
For i = 0 To ListBox1.SelectedIndices.Count - 1
ListBox2.Items.Add(ListBox1.Items(ListBox1.SelectedIndices(0)))
ListBox1.Items.Remove(ListBox1.Items(ListBox1.SelectedIndices(0)))
Next
End Sub
Last edited by DigitalHand; Dec 23rd, 2003 at 05:12 PM.
-
Dec 24th, 2003, 02:51 AM
#4
Thread Starter
Fanatic Member
hi all,
writing code in loop was always easy. thats an orthodox vb6 way to do that. when addrange and removerange methods are given, why not utilise the stuff?
and kylek, ObjectCollection and SelectedObjectCollection is not working. i tried it earlier also. It gives me error that " 'ObjectCollection' is a type in 'System.Windows.Forms.ListBox' and cannot be used as an expression"
any further ideas pls??
regards,
prakash
-
Dec 24th, 2003, 05:07 AM
#5
Sleep mode
Play around with this code , it's 99 % done with little glitch , though , it might give you a clue .
VB Code:
Try
For i As Integer = 0 To Me.ListBox1.Items.Count
Me.ListBox2.Items.Add(Me.ListBox1.SelectedItems.Item(i))
Me.ListBox1.Items.Remove(Me.ListBox1.SelectedItems.Item(i))
Next
Catch ex As Exception
MsgBox(ex.Message)
End Try
-
Dec 24th, 2003, 05:49 AM
#6
just use an arraylist , one easy step ...
VB Code:
Dim lbCol As New ListBox.SelectedObjectCollection(ListBox1)
Dim arr As New ArrayList()
arr.AddRange(lbCol)
ListBox2.Items.AddRange(arr.ToArray)
~
if a post is resolved, please mark it as [Resolved]
protected string get_Signature(){return Censored;}
[vbcode][php] please use code tags when posting any code [/php][/vbcode]
-
Dec 24th, 2003, 06:10 AM
#7
i'm really cooking with gas today , here ya go
VB Code:
Dim lbCol As New ListBox.SelectedObjectCollection(ListBox1)
ListBox2.Items.AddRange(ArrayList.Adapter(lbCol).ToArray)
~
if a post is resolved, please mark it as [Resolved]
protected string get_Signature(){return Censored;}
[vbcode][php] please use code tags when posting any code [/php][/vbcode]
-
Dec 26th, 2003, 06:47 AM
#8
Thread Starter
Fanatic Member
thanx dynamic_sysop
its working. wot about removing the multi-selected items?? meanwhile i am removing it using loop as .RemoveRange method is not available. any other trick??
actually i am preparing a form having 2 ListBoxes between which items are selected and removed.
any help??
regards,
prakash
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|