Results 1 to 10 of 10

Thread: listbox properity?? help

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Nov 2002
    Posts
    18

    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

  2. #2
    Frenzied Member DevGrp's Avatar
    Join Date
    Nov 2001
    Location
    Charlotte, NC
    Posts
    1,256
    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

  3. #3
    Member
    Join Date
    Sep 2002
    Location
    California
    Posts
    52
    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

  4. #4

    Thread Starter
    Junior Member
    Join Date
    Nov 2002
    Posts
    18
    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.

  5. #5
    Member
    Join Date
    Sep 2002
    Location
    California
    Posts
    52
    If you want to remove something at a specific index then just use the RemoveAt() property.

  6. #6

    Thread Starter
    Junior Member
    Join Date
    Nov 2002
    Posts
    18
    no..i couldn't get that working..some exception error

  7. #7
    Member
    Join Date
    Sep 2002
    Location
    California
    Posts
    52
    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

  8. #8

    Thread Starter
    Junior Member
    Join Date
    Nov 2002
    Posts
    18

    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.

  9. #9
    Member
    Join Date
    Sep 2002
    Location
    California
    Posts
    52
    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).

  10. #10

    Thread Starter
    Junior Member
    Join Date
    Nov 2002
    Posts
    18

    Talking 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
  •  



Click Here to Expand Forum to Full Width