473,320 Members | 1,872 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Listview SubItems image index

This is probably a silly question but oh well, I can't find the answer
looking via code.

Having an imagelist already, how does one set an icon for a list view's sub
items?

I'm using the code below however the subitems doesn't have an overload
allowing an image index.

Adam

***Code***

lvItem = lvControl.Items.Add(sData, 0)

sData = ReadINIFileValue(INI_SECTION_TYPE1 + " " + CType(iCounter, String),
"Program name", MyAccountsINIFilePath)

lvItem.SubItems.Add(sData) <-------- Cannot add image index here
Apr 19 '06 #1
10 12220
Adam,

The simplest method to find this kind of methods is to look how it is done
in the designer.
Therefore create a small project, do this using the designer and see how
they done it. I have not seen yet code made by the designer that was stupid
done.

I hope this helps,

Cor

"Adam Honek" <Ad*******@Webmaster2001.freeserve.co.uk> schreef in bericht
news:eN**************@TK2MSFTNGP02.phx.gbl...
This is probably a silly question but oh well, I can't find the answer
looking via code.

Having an imagelist already, how does one set an icon for a list view's
sub items?

I'm using the code below however the subitems doesn't have an overload
allowing an image index.

Adam

***Code***

lvItem = lvControl.Items.Add(sData, 0)

sData = ReadINIFileValue(INI_SECTION_TYPE1 + " " + CType(iCounter,
String), "Program name", MyAccountsINIFilePath)

lvItem.SubItems.Add(sData) <-------- Cannot add image index here

Apr 19 '06 #2
AFAIK, .NET does not built-in support for that. As alternative, see:

ListView with Image on SubItems
http://www.codeproject.com/cs/miscctrl/OAKListView.asp

--

Best regards,

Carlos J. Quintero

MZ-Tools: Productivity add-ins for Visual Studio
You can code, design and document much faster:
http://www.mztools.com
"Adam Honek" <Ad*******@Webmaster2001.freeserve.co.uk> escribi en el
mensaje news:eN**************@TK2MSFTNGP02.phx.gbl...
This is probably a silly question but oh well, I can't find the answer
looking via code.

Having an imagelist already, how does one set an icon for a list view's
sub items?

I'm using the code below however the subitems doesn't have an overload
allowing an image index.

Adam

***Code***

lvItem = lvControl.Items.Add(sData, 0)

sData = ReadINIFileValue(INI_SECTION_TYPE1 + " " + CType(iCounter,
String), "Program name", MyAccountsINIFilePath)

lvItem.SubItems.Add(sData) <-------- Cannot add image index here

Apr 19 '06 #3
Hello!
We are currently working on a PocketPc application in vb.net 2005.It is
reqired that we use a ListView , but with images in the sub items.
I tried the link below...

http://www.codeproject.com/cs/miscctrl/OAKListView.asp

I has some problems when trying to convert the c# code to VB.

In particular the SendMessage() function call in the Button_clickevent
throws a System.NotSupportedException ...

Could anyone suggest a solution or provide a link with VB.NET coding for the
above problem..?

Thanks,
"Adam Honek" wrote:
This is probably a silly question but oh well, I can't find the answer
looking via code.

Having an imagelist already, how does one set an icon for a list view's sub
items?

I'm using the code below however the subitems doesn't have an overload
allowing an image index.

Adam

***Code***

lvItem = lvControl.Items.Add(sData, 0)

sData = ReadINIFileValue(INI_SECTION_TYPE1 + " " + CType(iCounter, String),
"Program name", MyAccountsINIFilePath)

lvItem.SubItems.Add(sData) <-------- Cannot add image index here

Apr 19 '06 #4
Hello!
We are currently working on a PocketPC application in vb.net 2005.It is
reqired that we use a ListView , but with images in the sub items.
I tried the link below...

http://www.codeproject.com/cs/miscctrl/OAKListView.asp

I has some problems when trying to convert the c# code to VB.

In particular the SendMessage() function call in the Button_clickevent
throws a System.NotSupportedException ...

Could anyone suggest a solution or provide a link with VB.NET coding for the
above problem..?
Thank You,
"Carlos J. Quintero [VB MVP]" wrote:
AFAIK, .NET does not built-in support for that. As alternative, see:

ListView with Image on SubItems
http://www.codeproject.com/cs/miscctrl/OAKListView.asp

--

Best regards,

Carlos J. Quintero

MZ-Tools: Productivity add-ins for Visual Studio
You can code, design and document much faster:
http://www.mztools.com
"Adam Honek" <Ad*******@Webmaster2001.freeserve.co.uk> escribió en el
mensaje news:eN**************@TK2MSFTNGP02.phx.gbl...
This is probably a silly question but oh well, I can't find the answer
looking via code.

Having an imagelist already, how does one set an icon for a list view's
sub items?

I'm using the code below however the subitems doesn't have an overload
allowing an image index.

Adam

***Code***

lvItem = lvControl.Items.Add(sData, 0)

sData = ReadINIFileValue(INI_SECTION_TYPE1 + " " + CType(iCounter,
String), "Program name", MyAccountsINIFilePath)

lvItem.SubItems.Add(sData) <-------- Cannot add image index here


Apr 19 '06 #5
The following should work (hope I remembered everything). You can change
Friend to Public or so if you want:

<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
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
Win32.Native.LVITEM) As Boolean
Return CBool(Win32.Native.SendMessage(hwnd, Win32.Native.LVM_GETITEM,
IntPtr.Zero, lvi))
End Function

Friend Overloads Declare Auto Function SendMessage Lib "User32.dll" (ByVal
hwnd As IntPtr, ByVal msg As Integer, ByVal wParam As IntPtr, ByRef lParam
As Win32.Native.LVITEM) As Integer
Friend Overloads Declare Auto 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_SetItem(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
You need the following call to enable support for sub item images (put it in
a CreateControl event handler or override)
SendMessage(myListView.Handle, LVM_SETEXTENDEDLISTVIEWSTYLE,
LVS_EX_SUBITEMIMAGES, LVS_EX_SUBITEMIMAGES)
/claes

"Adam Honek" <Ad*******@Webmaster2001.freeserve.co.uk> wrote in message
news:eN**************@TK2MSFTNGP02.phx.gbl...
This is probably a silly question but oh well, I can't find the answer
looking via code.

Having an imagelist already, how does one set an icon for a list view's
sub items?

I'm using the code below however the subitems doesn't have an overload
allowing an image index.

Adam

***Code***

lvItem = lvControl.Items.Add(sData, 0)

sData = ReadINIFileValue(INI_SECTION_TYPE1 + " " + CType(iCounter,
String), "Program name", MyAccountsINIFilePath)

lvItem.SubItems.Add(sData) <-------- Cannot add image index here

Apr 19 '06 #6
Hmm I think something's missing from this code somewhere such as no
reference to Marshal???

It's odd how VB6 had icons in listview subitems but not .Net.

I understand that we need to do the sendmessage() say in a form_load to
activate the option in our listview
in .Net as stated below but how do we actually add the image to the subitem?

Do we need to call ListView_SetSubItemImageIndex() after adding the subitem
to the LV as normal?

Thanks,
Adam

"Claes Bergefall" <lo*****@nospam.nospam> wrote in message
news:OM**************@TK2MSFTNGP02.phx.gbl...
The following should work (hope I remembered everything). You can change
Friend to Public or so if you want:

<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
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
Win32.Native.LVITEM) As Boolean
Return CBool(Win32.Native.SendMessage(hwnd, Win32.Native.LVM_GETITEM,
IntPtr.Zero, lvi))
End Function

Friend Overloads Declare Auto Function SendMessage Lib "User32.dll" (ByVal
hwnd As IntPtr, ByVal msg As Integer, ByVal wParam As IntPtr, ByRef lParam
As Win32.Native.LVITEM) As Integer
Friend Overloads Declare Auto 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_SetItem(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
You need the following call to enable support for sub item images (put it
in a CreateControl event handler or override)
SendMessage(myListView.Handle, LVM_SETEXTENDEDLISTVIEWSTYLE,
LVS_EX_SUBITEMIMAGES, LVS_EX_SUBITEMIMAGES)
/claes

"Adam Honek" <Ad*******@Webmaster2001.freeserve.co.uk> wrote in message
news:eN**************@TK2MSFTNGP02.phx.gbl...
This is probably a silly question but oh well, I can't find the answer
looking via code.

Having an imagelist already, how does one set an icon for a list view's
sub items?

I'm using the code below however the subitems doesn't have an overload
allowing an image index.

Adam

***Code***

lvItem = lvControl.Items.Add(sData, 0)

sData = ReadINIFileValue(INI_SECTION_TYPE1 + " " + CType(iCounter,
String), "Program name", MyAccountsINIFilePath)

lvItem.SubItems.Add(sData) <-------- Cannot add image index here


Apr 20 '06 #7


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
"Claes Bergefall" wrote:
The following should work (hope I remembered everything). You can change
Friend to Public or so if you want:

<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
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
Win32.Native.LVITEM) As Boolean
Return CBool(Win32.Native.SendMessage(hwnd, Win32.Native.LVM_GETITEM,
IntPtr.Zero, lvi))
End Function

Friend Overloads Declare Auto Function SendMessage Lib "User32.dll" (ByVal
hwnd As IntPtr, ByVal msg As Integer, ByVal wParam As IntPtr, ByRef lParam
As Win32.Native.LVITEM) As Integer
Friend Overloads Declare Auto 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_SetItem(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
You need the following call to enable support for sub item images (put it in
a CreateControl event handler or override)
SendMessage(myListView.Handle, LVM_SETEXTENDEDLISTVIEWSTYLE,
LVS_EX_SUBITEMIMAGES, LVS_EX_SUBITEMIMAGES)
/claes

"Adam Honek" <Ad*******@Webmaster2001.freeserve.co.uk> wrote in message
news:eN**************@TK2MSFTNGP02.phx.gbl...
This is probably a silly question but oh well, I can't find the answer
looking via code.

Having an imagelist already, how does one set an icon for a list view's
sub items?

I'm using the code below however the subitems doesn't have an overload
allowing an image index.

Adam

***Code***

lvItem = lvControl.Items.Add(sData, 0)

sData = ReadINIFileValue(INI_SECTION_TYPE1 + " " + CType(iCounter,
String), "Program name", MyAccountsINIFilePath)

lvItem.SubItems.Add(sData) <-------- Cannot add image index here


Apr 20 '06 #8
Hi,
While trying to use your VB code, I found that you had written the
SendMessage as…

Friend Overloads Declare Auto Function SendMessage Lib "User32.dll" (ByVal _
hwnd As IntPtr, ByVal msg As Integer, ByVal wParam As IntPtr, ByRef
lParam _
As LVITEM) As Integer

Using “auto” is not allowed in .NetCompactFramework…
I get the error message
“ The Targeted version of the .NetCompactFramework does not support using
the Ansi,Auto, or Unicode modifier”

So I used it as
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

Could My not using “auto” result in “An unhandled exception of type
'System.MissingMethodException' occurred in ListView2.exe”

I’m stuck… Please shed some light on this …

Thanks,
"Claes Bergefall" wrote:
The following should work (hope I remembered everything). You can change
Friend to Public or so if you want:

<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
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
Win32.Native.LVITEM) As Boolean
Return CBool(Win32.Native.SendMessage(hwnd, Win32.Native.LVM_GETITEM,
IntPtr.Zero, lvi))
End Function

Friend Overloads Declare Auto Function SendMessage Lib "User32.dll" (ByVal
hwnd As IntPtr, ByVal msg As Integer, ByVal wParam As IntPtr, ByRef lParam
As Win32.Native.LVITEM) As Integer
Friend Overloads Declare Auto 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_SetItem(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
You need the following call to enable support for sub item images (put it in
a CreateControl event handler or override)
SendMessage(myListView.Handle, LVM_SETEXTENDEDLISTVIEWSTYLE,
LVS_EX_SUBITEMIMAGES, LVS_EX_SUBITEMIMAGES)
/claes

"Adam Honek" <Ad*******@Webmaster2001.freeserve.co.uk> wrote in message
news:eN**************@TK2MSFTNGP02.phx.gbl...
This is probably a silly question but oh well, I can't find the answer
looking via code.

Having an imagelist already, how does one set an icon for a list view's
sub items?

I'm using the code below however the subitems doesn't have an overload
allowing an image index.

Adam

***Code***

lvItem = lvControl.Items.Add(sData, 0)

sData = ReadINIFileValue(INI_SECTION_TYPE1 + " " + CType(iCounter,
String), "Program name", MyAccountsINIFilePath)

lvItem.SubItems.Add(sData) <-------- Cannot add image index here


Apr 20 '06 #9
Kind of hard to tell since I have no experience at all with PocketPC or the
compact framework
Verify that the method is really called SendMessage (might be SendMessageA
or SendMessageW) and that it really is located in user32.dll (it is on
normal windows, maybe it's different on PocketPC).

As for the MarshalAs attribute, just try removing it (the String datatype is
still supported I hope)

/claes

"LProgrammer" <LP*********@discussions.microsoft.com> wrote in message
news:DC**********************************@microsof t.com...
Hi,
While trying to use your VB code, I found that you had written the
SendMessage as.

Friend Overloads Declare Auto Function SendMessage Lib "User32.dll" (ByVal
_
hwnd As IntPtr, ByVal msg As Integer, ByVal wParam As IntPtr, ByRef
lParam _
As LVITEM) As Integer

Using "auto" is not allowed in .NetCompactFramework.
I get the error message
" The Targeted version of the .NetCompactFramework does not support using
the Ansi,Auto, or Unicode modifier"

So I used it as
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

Could My not using "auto" result in "An unhandled exception of type
'System.MissingMethodException' occurred in ListView2.exe"

I'm stuck. Please shed some light on this .

Thanks,
"Claes Bergefall" wrote:
The following should work (hope I remembered everything). You can change
Friend to Public or so if you want:

<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
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
Win32.Native.LVITEM) As Boolean
Return CBool(Win32.Native.SendMessage(hwnd, Win32.Native.LVM_GETITEM,
IntPtr.Zero, lvi))
End Function

Friend Overloads Declare Auto Function SendMessage Lib "User32.dll"
(ByVal
hwnd As IntPtr, ByVal msg As Integer, ByVal wParam As IntPtr, ByRef
lParam
As Win32.Native.LVITEM) As Integer
Friend Overloads Declare Auto 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_SetItem(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
You need the following call to enable support for sub item images (put it
in
a CreateControl event handler or override)
SendMessage(myListView.Handle, LVM_SETEXTENDEDLISTVIEWSTYLE,
LVS_EX_SUBITEMIMAGES, LVS_EX_SUBITEMIMAGES)
/claes

"Adam Honek" <Ad*******@Webmaster2001.freeserve.co.uk> wrote in message
news:eN**************@TK2MSFTNGP02.phx.gbl...
> This is probably a silly question but oh well, I can't find the answer
> looking via code.
>
> Having an imagelist already, how does one set an icon for a list view's
> sub items?
>
> I'm using the code below however the subitems doesn't have an overload
> allowing an image index.
>
> Adam
>
> ***Code***
>
> lvItem = lvControl.Items.Add(sData, 0)
>
> sData = ReadINIFileValue(INI_SECTION_TYPE1 + " " + CType(iCounter,
> String), "Program name", MyAccountsINIFilePath)
>
> lvItem.SubItems.Add(sData) <-------- Cannot add image index here
>
>


Apr 20 '06 #10

"Adam Honek" <Ad*******@Webmaster2001.freeserve.co.uk> wrote in message
news:un**************@TK2MSFTNGP02.phx.gbl...
Hmm I think something's missing from this code somewhere such as no
reference to Marshal???
Not sure what you mean. Marshal (and MarshalAs attribute) is a framework
class

It's odd how VB6 had icons in listview subitems but not .Net.

I understand that we need to do the sendmessage() say in a form_load to
activate the option in our listview
in .Net as stated below but how do we actually add the image to the
subitem?

Do we need to call ListView_SetSubItemImageIndex() after adding the
subitem to the LV as normal?


Yes
/claes
Apr 20 '06 #11

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: John Lauwers | last post by:
I know you can edit the first column of the listview control, is there a way to edit the second and/or the other columns? greets John
0
by: Mike Barrett | last post by:
I have a strange one here and I believe it is a bug. I googled it and saw others having a similar issue and nobody seems to have a fix. I will take another shot. I get this ERROR MESSAGE... ...
3
by: andrewcw | last post by:
I have a simple winform with the following code. But although I can read back the info, the display fails to provide the text or the cell background color changes. private void ListViewBroke()...
0
by: Samuel R. Neff | last post by:
I'm having a index problem with ListView SubItems. If I add multiple columns to the listview and then add items with associated subitems, the ListView displays fine. Then if I delete a column via...
0
by: Mike Barrett | last post by:
I have a strange one here and I believe it is a bug. I googled it and saw others having a similar issue and nobody seems to have a fix. I will take another shot. I get this ERROR MESSAGE... ...
1
by: Mamatha | last post by:
Hi I have one application ,that diplays data from database into the listview control.While adding data to the listview i want to display an icon to the leftside of the first column's data.Here...
6
by: Jack | last post by:
Hello, I've noticed through searching this group's previous posts that one can get the item the mouse is over in a listview control but I did not see how to get the subitem the mouse is over. Is...
2
by: mrmagoo | last post by:
I'm trying to fill a listview with data. I'm using the example from the help file, but how do I modify this to avoid using images? I want the exact same layout but without images. This procedure...
11
by: Alan T | last post by:
Does the ListView supports sort? I want to have a up/down arrow/triangle that show it is sorted asc or desc on the column headers when I click the column header. May be I need a third-party...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, youll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.