|
-
Dec 1st, 2002, 05:10 PM
#1
Thread Starter
Junior Member
listbox properity?? help
Hi
there's a function or properity associated with the following:
lstBox1.items.remove(lstBox1.selectedItems)
lstBox2.items.remove(lstBox2.?????)
my goal is to remove an item from lstBox1 by selecting it and automatically item on tthe same index from lstBox2 gets removed automatically w/o having to select it.
now i know it should be lstBox1.selctedItems in lstBox1. what shall i use for the lstBox2 and possibly lstBox3
P.S i have option strict and option (i forgot wt is ) are on.
thanks
-
Dec 1st, 2002, 05:24 PM
#2
Frenzied Member
I'm not at home but try something like this.
Check to see if the selected item in listbox1 is in the items collection in listbox2, then remove it using the index.
I'll try it when I get home.
Dont gain the world and lose your soul
-
Dec 1st, 2002, 06:39 PM
#3
Member
Okay, so whenever the user selects an item in ListBox1, you want to remove that exact item from both ListBox1 and ListBox2? Try this;
Code:
Private Sub ListBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) _
Handles ListBox1.SelectedIndexChanged
ListBox2.Items.Remove(ListBox1.SelectedItem)
ListBox1.Items.Remove(ListBox1.SelectedItem)
End Sub
-
Dec 1st, 2002, 08:15 PM
#4
Thread Starter
Junior Member
well , it's more like selecting an index and then once u decide to remove it , u click on cmdRemove , which then removes it and items of the same index on different lstBoxes
say u want to remove an item, once it removed, its price and quantity disappears as well.
-
Dec 1st, 2002, 08:44 PM
#5
Member
If you want to remove something at a specific index then just use the RemoveAt() property.
-
Dec 1st, 2002, 09:02 PM
#6
Thread Starter
Junior Member
no..i couldn't get that working..some exception error
-
Dec 1st, 2002, 09:12 PM
#7
Member
Code:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
ListBox2.Items.RemoveAt(ListBox1.SelectedIndex)
ListBox1.Items.RemoveAt(ListBox1.SelectedIndex)
End Sub
-
Dec 1st, 2002, 09:19 PM
#8
Thread Starter
Junior Member
here's the code
i tried it agin but not working..here's the exception:
An unhandled exception of type 'System.ArgumentOutOfRangeException' occurred in system.windows.forms.dll
Additional information: Specified argument was out of the range of valid values.
and here's the actual code:
Private Sub cmdRemove_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdRemove.Click
Dim selectedItem As Integer
If lstProduct.SelectedIndex <> -1 Then
lstProduct.Items.RemoveAt(lstProduct.SelectedIndex)
lstQuantity.Items.RemoveAt(lstQuantity.SelectedIndex)
lstCost.Items.RemoveAt(lstCost.SelectedIndex)
quantity = CInt(lstQuantity.SelectedIndex)
totalQuantity = (totalQuantity - quantity)
lblTotalQuantity.Text = CStr(totalQuantity)
cost = CDec(lstCost.SelectedIndex)
totalCost = (totalCost - cost)
lblTotalCost.Text = CStr(totalCost)
Else
MsgBox("PLease select an item to be removed")
End If
End Sub
oh..thanks again for helping me out man.
-
Dec 1st, 2002, 09:41 PM
#9
Member
You said that you wanted to remove the specific selected index from multiple ListBox's based on what was selected in the 1st ListBox.
In your code you're trying to remove items based on their own selected items and are only checking if lstProduct has an invalid selection.
After you have the remove index code you are then trying to set variables based on the selected items (which you removed!). Obviously that's going to be invalid as well.
You need to set the cost and quantity before you remove the selected items then remove the items based off one ListBox's selected item being sure to remove from that ListBox last (otherwise you'll get errors again because you removed the selection).
-
Dec 1st, 2002, 10:10 PM
#10
Thread Starter
Junior Member
thank u very much
man, i would like to thank u very much for helping me out..it worked like magic...i'm probably gonna come back soon?? for more problems. then again if i find people like u, then it shouldn't be hard to find help in here..
again thank u very much
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
|