CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Guest

    DATA between litsboxes

    how do I make it so when an item is clicked into list1, it is entered in the same spot in list2. I tried the following code:

    Private Sub List1_Click()
    a = list1.listindex
    b$ = list1.list(a)
    list2.additem b$, a

    but when I try it, it keeps saying "INVALID PROCEDURE CALL OR ARGUEMENT..." What is wrong?






  2. #2
    Join Date
    Dec 1999
    Location
    Austria
    Posts
    17

    Re: DATA between litsboxes

    if you run your programm, the line:
    list2.additem b$, a
    makes the problem!
    it only works, if you select the first item from list1 (a = 0),
    if you select the 2nd 3rd... item it doesn't work, because you cannot add
    a item to your list2 with index 1 2 3..., if the listbox is empty or has less than index(n) items
    better you use list2.additem b$

    i hope i could help you


  3. #3
    Join Date
    Dec 1999
    Location
    Malaysia
    Posts
    56

    Re: DATA between litsboxes

    hi,
    I think I can explain why there is a problem with your code. For example, I have a list:
    "A"
    "B"
    "C"
    and would like to add this from one listbox to another listbox when the user clicks on one of the items:


    private Sub lstFirstBox_Click()
    lstSecondBox.AddItem lstFirstBox.List lstFirstBox.ListIndex), lstFirstBox.ListIndex
    End Sub




    An error would occur if you click on B or C as when you try to add these items to the second listbox, the elements before are not added, since the "AddItem" method adds items to a listbox incremently from 0.

    So, a workaround to this is to check if the first element has been chosen or not:


    private Sub lstFirstBox_Click()

    If (lstFirstBox.ListIndex = 1) then
    'Add some dummy lines
    lstSecondBox.AddItem vbNullString, 0
    lstSecondBox.AddItem lstFirstBox.List(lstFistBox.ListIndex), lstFirstBox.ListIndex
    ElseIf (lstFirstBox.ListIndex = 2) then
    'Add 2 dummy lines
    lstSecondBox.AddItem vbNullString, 0
    lstSecondBox.AddItem vbNullString, 1
    else
    lstSecondBox.AddItem lstFirstBox.List(lstFirstBox.ListIndex), lstFirstBox.ListIndex
    End If
    End Sub




    Here, I've done a little checking to see if the first element was clicked or not, if either B or C was clicked, an empty string will be added to the listbox.

    Hope this does clears a few things up... try it!



    ____________________________________
    The VB Bugs in my Life...

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

Featured