Results 1 to 5 of 5
  1. #1
    2 Star Lounger
    Join Date
    Apr 2003
    Location
    England
    Posts
    124
    Thanks
    0
    Thanked 0 Times in 0 Posts

    listbox drag and drop (office2002 widowsxp)

    i found what i was looking for and i was able to convert it so that i could use a data base on sheet 2. drag and drop works fine but as soon as i start to try an include a third listbox so that i might drag and drop to the second list box , nothing happens.

    can any one help or suggest a solution

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: listbox drag and drop (office2002 widowsxp)

    I'm confused by the userform in your attachment. It contains list boxes named ListBox1 and ListBox2, but the latter is labeled ListBox3. There is code for ListBox1, ListBox2 and ListBox3, but there is no ListBox3 on the userform.

  3. #3
    2 Star Lounger
    Join Date
    Apr 2003
    Location
    England
    Posts
    124
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: listbox drag and drop (office2002 widowsxp)

    if you were confused so was i and i appologise for that. If the second list box was renamed listbox 3, and the properties were changed from " LISTBOX2 To LISTBOX3" all works out OK.
    if i am correct i could have listbox1, listbox3, listbox4 ect. and drag and drop from any of the listboxes to listbox2 which in my case is great.
    'Private Sub ListBox3_MouseMove(ByVal Button As Integer, ByVal Shift As Integer, ByVal X As Single, ByVal Y As Single) ## change listbox3 or 4 or 5 or 6'Dim MyDataObject As DataObject
    ' If Button = 1 Then
    ' Set MyDataObject = New DataObject
    ' Dim Effect As Integer
    ' MyDataObject.SetText ListBox3.Value '############## these are the only lines which has to be changed listbox3 or 4 or 5 or 6 ################
    ' Effect = MyDataObject.StartDrag
    'End If
    'End Sub


    sorry for any confusion also my delay for relying sooner is that i have had a short break.
    thank you for all your trouble
    alex

  4. #4
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: listbox drag and drop (office2002 widowsxp)

    That is possible, but there is another problem: ListBox2 is now populated from a range (Sheet2!I2:O180). You can't add items to a list box that is bound to a spreadsheet range. Instead, you must populate the list box in the Initialize event of the userform:

    Private Sub UserForm_Initialize()
    Dim i As Integer, j As Integer
    Dim n As Integer
    n = Sheets("sheet2").Range("I65536").End(xlUp).Row
    ReDim arr(1 To n - 1, 1 To 7)
    For i = 1 To n - 1
    For j = 1 To 7
    arr(i, j) = Sheets("Sheet2").Cells(i + 1, j + 8)
    Next j
    Next i
    Me.ListBox2.List = arr
    Erase arr
    End Sub

    You must also set the ColumnHeads property of ListBox2 to False, for ColumnHeads = True only works for a list box bound to a spreadsheet range.

  5. #5
    2 Star Lounger
    Join Date
    Apr 2003
    Location
    England
    Posts
    124
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: listbox drag and drop (office2002 widowsxp)

    pls bear with me, i have to go out to re-stock our larder after our hols, but see attachment in the meantime. once i have recovered from the journey i will look at the file again.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •