• Privacywetgeving
    Het is bij Helpmij.nl niet toegestaan om persoonsgegevens in een voorbeeld te plaatsen. Alle voorbeelden die persoonsgegevens bevatten zullen zonder opgaaf van reden verwijderd worden. In de vraag zal specifiek vermeld moeten worden dat het om fictieve namen gaat.

listbox gegevens

Status
Niet open voor verdere reacties.

tobo100

Gebruiker
Lid geworden
14 okt 2013
Berichten
153
Hallo allemaal,

ik heb een userform met daar op 2 listboxen
1 lstdata vult zich via rowsource 5 kolommen
2 ListBox2 wil ik graag vullen door op een regel in lstdata te dubbelklikken

Met onderstaande code lukt dit gedeeltelijk, onderstaande code vult listbox2 alleen maar in de eerste kolom
mijn vraag is nu : kan iemand mij helpen met een code die alle 5 kolommen vult (Kopieert) van lstdata naar listbox2 d.m.v. dubbel klikken op een regel



PHP:
Sub Get_ListBox_Selected_Items()
Dim iCnt As Integer
For iCnt = 0 To lstdata.ListCount - 1
If lstdata.Selected(iCnt) = True Then
ListBox2.AddItem lstdata.List(iCnt)
End If
Next
End Sub
 
Plaats het bestand eens.
 
werkt dit zoals je wilt?

Code:
Private Sub lstdata_DblClick(ByVal Cancel As MSForms.ReturnBoolean)
Dim iCnt, i As Integer
    For iCnt = 0 To lstdata.ListCount - 1
        If lstdata.Selected(iCnt) = True Then
        i = ListBox2.ListCount
            With ListBox2
                .AddItem
                .List(i, 0) = lstdata.List(iCnt, 0)
                .List(i, 1) = lstdata.List(iCnt, 1)
                .List(i, 2) = lstdata.List(iCnt, 2)
                .List(i, 3) = lstdata.List(iCnt, 3)
                .List(i, 4) = lstdata.List(iCnt, 4)
            End With
        End If
    Next
End Sub
 
Code:
Kan ook zo!
With ListBox2
[COLOR=#0000ff]                .AddItem lstdata.List(iCnt, 0)[/COLOR]
                .List(i, 1) = lstdata.List(iCnt, 1)
                .List(i, 2) = lstdata.List(iCnt, 2)
                .List(i, 3) = lstdata.List(iCnt, 3)
                .List(i, 4) = lstdata.List(iCnt, 4)
            End With

Of:
Code:
With ListBox2
                .AddItem lstdata.List(iCnt, 0)
                  for j = 1 to 4
                   .List(i, j) = lstdata.List(iCnt, j)
                  next j
            End With
 
en nog een optie
Code:
Private Sub lstdata_DblClick(ByVal Cancel As MSForms.ReturnBoolean)
Dim i As Integer
lijst = lstdata.List

For i = 0 To lstdata.ListCount - 1
  If lstdata.Selected(i) = True Then
   For j = 0 To ListBox2.ColumnCount
    c00 = c00 & "|" & lijst(i, j)
     Next
    ListBox2.Column = Split(Mid(c00, 2), "|")
  End If
Next
End Sub

of iets korter kan ook
Code:
Private Sub lstdata_DblClick(ByVal Cancel As MSForms.ReturnBoolean)
Dim i As Integer
lijst = lstdata.List
   For j = 0 To ListBox2.ColumnCount
    c00 = c00 & "|" & lijst(lstdata.ListIndex, j)
     Next
    ListBox2.Column = Split(Mid(c00, 2), "|")
End Sub
 
Laatst bewerkt:
Volgens mij wil Ts bij elke dubbelklik de waarden bijzetten in Listbox2.
Code:
Private Sub lstdata_DblClick(ByVal Cancel As MSForms.ReturnBoolean)
Dim i As Long, j As Long, x As Long
ReDim arr(lstdata.ColumnCount, 0)
If ListBox2.ListCount = 0 Then
    For j = 0 To 4
      arr(j, x) = Choose(j + 1, "Rubriek", "Artikel", "Soort", "Omschrijving", "nog wat")
    Next j
    x = x + 1
   ReDim Preserve arr(lstdata.ColumnCount, x)
   Else
 Erase arr
 ReDim arr(lstdata.ColumnCount, 0)
End If
For i = 0 To ListBox2.ListCount - 1
    For j = 0 To ListBox2.ColumnCount - 1
     arr(j, x) = ListBox2.List(i, j)
    Next
     x = x + 1
     ReDim Preserve arr(lstdata.ColumnCount, x)
Next i
For i = 0 To lstdata.ListCount - 1
 If lstdata.Selected(i) Then
     For j = 0 To lstdata.ColumnCount - 1
       arr(j, x) = lstdata.List(i, j)
     Next j
    x = x + 1
       ReDim Preserve arr(lstdata.ColumnCount, x)
  End If
Next i
ReDim Preserve arr(lstdata.ColumnCount, x - 1)
ListBox2.List = Application.Transpose(arr)
End Sub
 
Status
Niet open voor verdere reacties.
Steun Ons

Nieuwste berichten

Terug
Bovenaan Onderaan