|
- Option Explicit
- Dim arr
- Private Sub cmd查询_Click()
- Dim i&, j%, Item As MSComctlLib.ListItem
- ListView1.ListItems.Clear
- For i = 2 To UBound(arr)
- If arr(i, 3) Like "*" & TextBox1.Text & "*" Then
- Set Item = ListView1.ListItems.Add(, , arr(i, 2))
- For j = 3 To 9
- Item.SubItems(j - 2) = arr(i, j)
- Next
- End If
- Next
- If ListView1.ListItems.Count > 0 Then
- ListView1.SetFocus
- ListView1.SelectedItem.Selected = True
- End If
- End Sub
- Private Sub TextBox1_KeyDown(ByVal KeyCode As MSForms.ReturnInteger, ByVal Shift As Integer)
- If KeyCode = 13 Then cmd查询_Click
- End Sub
- Private Sub ListView1_DblClick()
- Dim R&, Item As MSComctlLib.ListItem
- R = ActiveCell.Row
- Set Item = ListView1.SelectedItem
- Cells(R, 10) = Item.Text
- Cells(R, 11) = Item.SubItems(1)
- Cells(R, 12) = Item.SubItems(2)
- Cells(R, 13) = Item.SubItems(3)
- Cells(R, 14) = Item.SubItems(4)
- Cells(R, 15) = Item.SubItems(5)
- Cells(R, 16) = Item.SubItems(6)
- Cells(R, 18) = Item.SubItems(7)
- Cells(R, 19).FormulaR1C1 = "=R" & R & "C[-2]*R" & R & "C[-1]"
- Me.Hide
- End Sub
- Private Sub ListView1_KeyDown(KeyCode As Integer, ByVal Shift As Integer)
- If KeyCode = 13 Then ListView1_DblClick
- End Sub
- Private Sub UserForm_Activate()
- If ListView1.ListItems.Count > 0 Then
- ListView1.SetFocus
- ListView1.SelectedItem.Selected = True
- End If
- End Sub
- Private Sub UserForm_Initialize()
- arr = Sheet3.Range("A1").CurrentRegion
- With ListView1
- .FullRowSelect = True
- .Gridlines = True
- .LabelEdit = lvwManual
- .MultiSelect = True
- .View = lvwReport
- Set .SmallIcons = ImageList1
- End With
- With ListView1.ColumnHeaders
- .Add , , "物品代码", 0
- .Add , , "物品名称", 90
- .Add , , "规格型号", 60
- .Add , , "类别", 60
- .Add , , "仓位", 60
- .Add , , "单位", 60
- .Add , , "类型", 60
- .Add , , "单价", 60
- End With
- Sheet1.Select
- cmd查询_Click
- End Sub
复制代码 |
|