• listbox drag and drop (office2002 widowsxp)

    Home » Forums » AskWoody support » Productivity software by function » Visual Basic for Applications » listbox drag and drop (office2002 widowsxp)

    Author
    Topic
    #422201

    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

    Viewing 0 reply threads
    Author
    Replies
    • #962454

      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.

      • #963163

        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

        • #963168

          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.

          • #963235

            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.

    Viewing 0 reply threads
    Reply To: listbox drag and drop (office2002 widowsxp)

    You can use BBCodes to format your content.
    Your account can't use all available BBCodes, they will be stripped before saving.

    Your information: