7,765
社区成员
发帖
与我相关
我的任务
分享
Private Sub Form_Load()
Dim i As Byte
ListView1.Arrange = lvwAutoLeft
ListView1.LabelWrap = False
ListView1.FlatScrollBar = False
ListView1.Sorted = True
ListView1.ListItems.Clear
ListView1.ColumnHeaders.Clear
ListView1.View = lvwReport
ListView1.AllowColumnReorder = True
ListView1.FullRowSelect = True
ListView1.GridLines = True
For i = 0 To 6
ListView1.ColumnHeaders.Add , , "列" & i
Next
For i = 0 To 6
Set sIitem = ListView1.ListItems.Add '显示出来
sIitem.Text = Left("0000000", 8 - Len(Str(i))) & i
sIitem.SubItems(1) = "型号"
sIitem.SubItems(2) = "名称"
sIitem.SubItems(3) = "技术资料"
sIitem.SubItems(4) = "生产许可证"
sIitem.SubItems(5) = "计量许可证"
sIitem.SubItems(6) = "制造商"
Next
End Sub
Private Type POINTAPI
X As Long
Y As Long
End Type
Private Type RECT
Left As Long
Top As Long
Right As Long
Bottom As Long
End Type
Private Type LVHITTESTINFO
pt As POINTAPI
flags As Long
iItem As Long
iSubItem As Long
End Type
Private Const LVI_NOITEM = -1
Private Const LVM_FIRST = &H1000
Private Const LVM_GETSUBITEMRECT = (LVM_FIRST + 56)
Private Const LVM_SUBITEMHITTEST = (LVM_FIRST + 57)
Private Const LVIR_ICON = 1
Private Const LVIR_LABEL = 2
Private Declare Function ScreenToClient Lib "user32" (ByVal hwnd As Long, lpPoint As POINTAPI) As Long
Private Declare Function GetCursorPos Lib "user32" (lpPoint As POINTAPI) As Long
Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" ( _
ByVal hwnd As Long, _
ByVal wMsg As Long, _
ByVal wParam As Long, _
lParam As Any) As Long
Private Sub listview1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
Dim iNdexs As Long
Dim xMove As Long
Dim yMove As Long
Dim rc As RECT
If Not ListView1.HitTest(X, Y) Is Nothing Then
Dim lvhti As LVHITTESTINFO
GetCursorPos lvhti.pt '转换到ListView中的位置
ScreenToClient ListView1.hwnd, lvhti.pt
If (ListView_SubItemHitTest(ListView1.hwnd, lvhti) <> LVI_NOITEM) Then '项目
Me.Caption = "当前位置第" & ListView1.HitTest(X, Y).Index & "行,第" & lvhti.iSubItem & "列"
End If
End If
End Sub
Private Sub Form_Load()
Dim i As Byte
ListView1.Arrange = lvwAutoLeft
ListView1.LabelWrap = False
ListView1.FlatScrollBar = False
ListView1.Sorted = True
ListView1.ListItems.Clear
ListView1.ColumnHeaders.Clear
ListView1.View = lvwReport
ListView1.AllowColumnReorder = True
ListView1.FullRowSelect = True
ListView1.GridLines = True
For i = 0 To 6
ListView1.ColumnHeaders.Add , , "列" & i
Next
For i = 0 To 6
Set sIitem = ListView1.ListItems.Add '显示出来
sIitem.Text = Left("0000000", 8 - Len(Str(n))) & n
sIitem.SubItems(1) = "型号"
sIitem.SubItems(2) = "名称"
sIitem.SubItems(3) = "技术资料"
sIitem.SubItems(4) = "生成许可证"
sIitem.SubItems(5) = "计量许可证"
sIitem.SubItems(6) = "制造商"
Next
End Sub
Private Function ListView_GetSubItemRect(hwnd As Long, iItem As Long, iSubItem As Long, _
code As Long, prc As RECT) As Boolean
prc.Top = iSubItem
SelectSubItem = iSubItem
prc.Left = code
ListView_GetSubItemRect = SendMessage(hwnd, LVM_GETSUBITEMRECT, ByVal iItem, prc)
End Function
Private Function ListView_SubItemHitTest(hwnd As Long, plvhti As LVHITTESTINFO) As Long
ListView_SubItemHitTest = SendMessage(hwnd, LVM_SUBITEMHITTEST, 0, plvhti)
End Function
Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
Const LVM_FIRST = &H1000
Const LVM_GETCOLUMNWIDTH = LVM_FIRST + 29
Private Sub ListView1_MouseDown(Button As Integer, Shift As Integer, x As Single, y As Single)
Dim RRow As Integer, CCol As Integer
RRow = ListView1.HitTest(x, y).Index
Dim a()
ReDim a(ListView1.ColumnHeaders.Count)
For i = 0 To ListView1.ColumnHeaders.Count - 1
a(i) = 15 * i * SendMessage(ListView1.hwnd, LVM_GETCOLUMNWIDTH, i, 0)
Next i
a(ListView1.ColumnHeaders.Count) = ListView1.Width
For i = 1 To ListView1.ColumnHeaders.Count
If x <= a(i) And x > a(i - 1) Then
CCol = i
Exit For
End If
Next i
Me.Caption = RRow & " " & CCol
End Sub