Hello!
I’m working on a Vb.net application tageting the PocketPc. So, it is
required that we write the code on .NetCompactFramework.
I need to create a ListView with 4 coulumns. It must have images on the
first 3 columns and text on the 4th.
Thank you for your code..I tried using your VB code…for my POcketPC
application in VB.Net (.NetCompactFramework) But was stuck with a few
errors…Can anybody help me out??
A few features like <marshal as> are not available in the
..NetCompactFrameWork.
So I had to make some modifications to your code…
Imports System.Runtime.InteropServices
------------------------------------------------------------------------------------------------
‘This class has a function to return the handle to any control
‘Since mylistview.Handle is not available in .NetcompactFramework
Class WinAPI
Public Declare Function SetCapture Lib "coredll.dll" (ByVal hWnd As
IntPtr) As IntPtr
Public Declare Function GetCapture Lib "coredll.dll" () As IntPtr
Public Shared Function GetHWnd(ByVal ctrl As Control) As IntPtr
Dim hOldWnd As IntPtr = GetCapture()
ctrl.Capture = True
Dim hWnd As IntPtr = GetCapture()
ctrl.Capture = False
SetCapture(hOldWnd)
Return hWnd
End Function
End Class
----------------------------------------------------------------------------------------------
Public Class Form1
Inherits System.Windows.Forms.Form
Friend WithEvents MainMenu1 As System.Windows.Forms.MainMenu
'<StructLayout(LayoutKind.Sequential, CharSet:=CharSet.Auto)> _
Friend Structure LVITEM
Friend mask As Integer
Friend iItem As Integer
Friend subItem As Integer
Friend state As Integer
Friend stateMask As Integer
'<MarshalAs(UnmanagedType.LPTStr)>Friend lpszText As String
‘MARSHAL AS IS NOT SUPPORTED CAN I USE BYTE()????
Friend lpszText As Byte()
Friend cchTextMax As Integer
Friend iImage As Integer
Friend lParam As IntPtr
Friend iIndent As Integer
End Structure
Friend Const LVM_FIRST As Integer = &H1000
Friend Const LVM_GETITEMA As Integer = LVM_FIRST + 5
Friend Const LVM_GETITEMW As Integer = LVM_FIRST + 75
Friend Shared ReadOnly LVM_GETITEM As Integer = _
CInt(IIf(Marshal.SystemDefaultCharSize = 1, LVM_GETITEMA, LVM_GETITEMW))
Friend Const LVM_SETITEMA As Integer = LVM_FIRST + 6
Friend Const LVM_SETITEMW As Integer = LVM_FIRST + 76
Friend Shared ReadOnly LVM_SETITEM As Integer = _
CInt(IIf(Marshal.SystemDefaultCharSize = 1, LVM_SETITEMA, LVM_SETITEMW))
Friend Const LVM_SETEXTENDEDLISTVIEWSTYLE As Integer = LVM_FIRST + 54
Friend Const LVIF_IMAGE As Integer = &H2
Friend Const LVS_EX_SUBITEMIMAGES As Integer = &H2
Friend Shared Function ListView_GetItem(ByVal hwnd As IntPtr, ByRef lvi
As LVITEM) As Boolean
Return CBool(SendMessage(hwnd, LVM_GETITEM, IntPtr.Zero, lvi))
End Function
Friend Overloads Declare Function SendMessage Lib "User32.dll" (ByVal _
hwnd As IntPtr, ByVal msg As Integer, ByVal wParam As IntPtr, ByRef
lParam _
As LVITEM) As Integer
Friend Overloads Declare Function SendMessage Lib "User32.dll" (ByVal _
hwnd As IntPtr, ByVal msg As Integer, ByVal wParam As Integer, ByVal
lParam _
As Integer) As Integer
Friend Shared Sub ListView_SetSubItemImageIndex(ByVal hwnd As IntPtr,
ByVal _
index As Integer, ByVal subItemIndex As Integer, ByVal imageIndex As _
Integer)
Dim lvi As LVITEM
lvi.iItem = index
lvi.subItem = subItemIndex
lvi.iImage = imageIndex
lvi.mask = LVIF_IMAGE
ListView_GetItem(hwnd, lvi)
End Sub
Friend Shared Function ListView_GetSubItemImageIndex(ByVal hwnd As
IntPtr, _
ByVal index As Integer, ByVal subItemIndex As Integer) As Integer
Dim lvi As LVITEM
lvi.iItem = index
lvi.subItem = subItemIndex
lvi.mask = LVIF_IMAGE
If ListView_GetItem(hwnd, lvi) Then
Return lvi.iImage
Else
Return -1
End If
End Function
#Region " Windows Form Designer generated code "
Public Sub New()
MyBase.New()
'This call is required by the Windows Form Designer.
InitializeComponent()
'Add any initialization after the InitializeComponent() call
'ImageList
'==========
Dim Img As New ImageList
Dim myImage As New Bitmap("/Program Files/ListView2/file.png")
Img.Images.Add(myImage)
'ListView
'=========
Dim MyListView As New ListView
MyListView.Location = New Point(0, 0)
MyListView.View = View.Details
MyListView.SmallImageList = Img
Dim ListItem1 As New ListViewItem
ListItem1.ImageIndex = 0
'How to define a subitem to be used in the call to
'ListView_GetSubItemImageIndex
'Dim ListSubItem1 As New ListViewItem.ListViewSubItem
'ListSubItem1.
‘Holds the handle to myListView
Dim hMyListView As IntPtr = WinAPI.GetHWnd(MyListView)
'SendMessage(MyListView.Handle, LVM_SETEXTENDEDLISTVIEWSTYLE, _
'LVS_EX_SUBITEMIMAGES, LVS_EX_SUBITEMIMAGES)
'MyListView.Handle is not available, so had to use a userdefined function to
obtain its handle...
SendMessage(hMyListView, LVM_SETEXTENDEDLISTVIEWSTYLE, _
LVS_EX_SUBITEMIMAGES, LVS_EX_SUBITEMIMAGES)
ListView_SetSubItemImageIndex(hMyListView, 0, 0, 0)
MyListView.Visible = True
End Sub
'Form overrides dispose to clean up the component list.
Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
MyBase.Dispose(disposing)
End Sub
'NOTE: The following procedure is required by the Windows Form Designer
'It can be modified using the Windows Form Designer.
'Do not modify it using the code editor.
Private Sub InitializeComponent()
Me.MainMenu1 = New System.Windows.Forms.MainMenu()
Me.Menu = Me.MainMenu1
Me.Text = "Form1"
End Sub
#End Region
End Class
=================================================
On debugging….
Exception 1: SendMessage()
An unhandled exception of type 'System.MissingMethodException' occurred in
ListView2.exe
Exception 2: ListView_GetItem()
An unhandled exception of type 'System.NotSupportedException' occurred in
ListView2.exe
How can I use SendMessage() in the vb.net on .net compactFramework??
How to make a call to ListView_SetSubItemImageIndex() with appropriate values.
Thanks for your help and valuble inputs

LProgrammer