lifeson
06-24-2008, 10:17 AM
I use this code to populate a listview and correctly displays the msg if there is only one item in the list.
With Me.lvwPackGroups
.ListItems.Clear
.HoverSelection = False
.LabelEdit = lvwManual
x = 1
For i = 2 To r
.ListItems.Add , , wsPgroup.Cells(i, "B").Value 'product ID
.ListItems(x).ListSubItems.Add , , wsPgroup.Cells(i, "E").Value
x = x + 1
Next i
If .ListItems.Count = 1 Then
'msgbox only 1 item is in list
'perform macro as though item was selected.
Else
'more than one item to coose from
End If
End With
If there is only 1 item I would like the routine that would normally run when that item is selected in the subsequent listview.
This is the routine for itemclick
Private Sub lvwPackGroups_ItemClick(ByVal item As MSComctlLib.ListItem)
Dim pCount As Long, x As Long, r As Long, idx As Long
Dim pkText As String
pckGrpID = item.Text
pckGrpdesc = item.SubItems(1)
idx = Application.WorksheetFunction.Match(pckGrpID, wsPgroup.Columns(2), 0)
pkText = wsPgroup.Cells(idx, "F").Value
Me.txtPkText.Value = pkText
Call QryPackGroupLink(pckGrpID)
pCount = wsPack.Cells(Rows.Count, "A").End(xlUp).row
With Me.lvwPacks
.ListItems.Clear
x = 1
For i = 2 To pCount
.ListItems.Add , , wsPack.Cells(i, "B").Value 'product ID
.ListItems(x).ListSubItems.Add , , wsPack.Cells(i, "E").Value
.ListItems(x).ListSubItems.Add , , wsPack.Cells(i, "C").Value
x = x + 1
Next i
End With
End Sub
Something like: Call lvwPackGroups_itemClick(1) ? :think: :doh:
With Me.lvwPackGroups
.ListItems.Clear
.HoverSelection = False
.LabelEdit = lvwManual
x = 1
For i = 2 To r
.ListItems.Add , , wsPgroup.Cells(i, "B").Value 'product ID
.ListItems(x).ListSubItems.Add , , wsPgroup.Cells(i, "E").Value
x = x + 1
Next i
If .ListItems.Count = 1 Then
'msgbox only 1 item is in list
'perform macro as though item was selected.
Else
'more than one item to coose from
End If
End With
If there is only 1 item I would like the routine that would normally run when that item is selected in the subsequent listview.
This is the routine for itemclick
Private Sub lvwPackGroups_ItemClick(ByVal item As MSComctlLib.ListItem)
Dim pCount As Long, x As Long, r As Long, idx As Long
Dim pkText As String
pckGrpID = item.Text
pckGrpdesc = item.SubItems(1)
idx = Application.WorksheetFunction.Match(pckGrpID, wsPgroup.Columns(2), 0)
pkText = wsPgroup.Cells(idx, "F").Value
Me.txtPkText.Value = pkText
Call QryPackGroupLink(pckGrpID)
pCount = wsPack.Cells(Rows.Count, "A").End(xlUp).row
With Me.lvwPacks
.ListItems.Clear
x = 1
For i = 2 To pCount
.ListItems.Add , , wsPack.Cells(i, "B").Value 'product ID
.ListItems(x).ListSubItems.Add , , wsPack.Cells(i, "E").Value
.ListItems(x).ListSubItems.Add , , wsPack.Cells(i, "C").Value
x = x + 1
Next i
End With
End Sub
Something like: Call lvwPackGroups_itemClick(1) ? :think: :doh: