Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Whats wrong with this?

Status
Not open for further replies.

MathTutor

Programmer
May 19, 2003
7
US
Trying to get Rectangular Coordanites for subitem of listview. Get error when double clicked.

Imports System
Imports System.Runtime.InteropServices
Public Class Form1
Inherits System.Windows.Forms.Form

Private Const LV_FIRST = &H1000
Private Const LV_GETCOLUMNWIDTH = (LV_FIRST + 29)
Private Const LV_GETTOPINDEX = (LV_FIRST + 39)
Private Const LV_SUBITEMREC = (LV_FIRST + 56)
Private Const LV_SUBITEMHITTEST = (LV_FIRST + 57)
Private Const LV_LABEL = 2
Private Const LV_ONITEMICON = &H2
Private Const LV_ONITEMLABEL = &H4
Private Const LV_ONITEMSTATEICON = &H8
Private Const LV_ONITEM = (&H2 Or &H4 Or &H8)


<StructLayout(layoutkind.sequential)> _
Private Structure POINTAPI
Dim X As Int32
Dim Y As Int32
End Structure

<StructLayout(LayoutKind.Sequential)> _
Private Structure RECT
Dim Left As Int32
Dim Right As Int32
Dim Top As Int32
Dim Bottom As Int32
End Structure

<StructLayout(LayoutKind.Sequential)> _
Private Structure LVINFO
Dim Pt As POINTAPI
Dim Flags As Int32
Dim Item As Int32
Dim Isubitem As Int32
End Structure

Dim Ipar As IntPtr
Dim LItem As ListViewItem
Dim LVdat As LVINFO
Dim Rc As RECT
<DllImport(&quot;user32.dll&quot;)> _
Private Shared Function sendmessage(ByVal Hwnd As IntPtr, ByVal msg As Int32, ByVal wParam As Int32, ByRef Iparam As IntPtr) As IntPtr
End Function


Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim ds As ListViewItem
Dim i%, j%
For i = 0 To 10
ds = New ListViewItem()
ds.Text = &quot;Carry &quot; & i
ds.SubItems.Add(&quot;John &quot; & i)
ds.SubItems.Add(&quot;Mary &quot; & i)
ds.SubItems.Add(&quot;Annie &quot; & i)
L.Items.Add(ds)
Next i
End Sub

Private Sub L_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles L.SelectedIndexChanged

End Sub

Private Sub L_MouseUp(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles L.MouseUp
With LVdat
.Pt.X = e.X
.Pt.Y = e.Y
.Flags = LV_ONITEM
End With
Tpx.Text = e.X
Tpy.Text = e.Y
End Sub

Private Sub L_DoubleClick(ByVal sender As Object, ByVal e As System.EventArgs) Handles L.DoubleClick
Dim Res As IntPtr
Dim TempRec As IntPtr
Ipar = Marshal.AllocCoTaskMem(Marshal.SizeOf(LVdat))
Marshal.StructureToPtr(LVdat, Ipar, False)
Res = sendmessage(L.Handle, LV_SUBITEMHITTEST, 0, Ipar)
If LVdat.Isubitem <> -1 Then
Rc.Left = LV_LABEL
Rc.Top = LVdat.Isubitem
TempRec = Marshal.AllocCoTaskMem(Marshal.SizeOf(Rc))
Marshal.StructureToPtr(Rc, TempRec, False)
Res = sendmessage(L.Handle, LV_SUBITEMREC, LVdat.Item, TempRec)
Tlx.Text = Rc.Left
Tly.Text = Rc.Right
Tlwidth.Text = Rc.Top
Tlhieght.Text = Rc.Bottom
End If
End Sub
End Class
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top