473,761 Members | 2,410 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 = ReadINIFileValu e(INI_SECTION_T YPE1 + " " + CType(iCounter, String),
"Program name", MyAccountsINIFi lePath)

lvItem.SubItems .Add(sData) <-------- Cannot add image index here
Apr 19 '06 #1
10 12298
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*******@Webm aster2001.frees erve.co.uk> schreef in bericht
news:eN******** ******@TK2MSFTN GP02.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 = ReadINIFileValu e(INI_SECTION_T YPE1 + " " + CType(iCounter,
String), "Program name", MyAccountsINIFi lePath)

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*******@Webm aster2001.frees erve.co.uk> escribió en el
mensaje news:eN******** ******@TK2MSFTN GP02.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 = ReadINIFileValu e(INI_SECTION_T YPE1 + " " + CType(iCounter,
String), "Program name", MyAccountsINIFi lePath)

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_clickeve nt
throws a System.NotSuppo rtedException ...

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 = ReadINIFileValu e(INI_SECTION_T YPE1 + " " + CType(iCounter, String),
"Program name", MyAccountsINIFi lePath)

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_clickeve nt
throws a System.NotSuppo rtedException ...

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*******@Webm aster2001.frees erve.co.uk> escribió en el
mensaje news:eN******** ******@TK2MSFTN GP02.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 = ReadINIFileValu e(INI_SECTION_T YPE1 + " " + CType(iCounter,
String), "Program name", MyAccountsINIFi lePath)

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(L ayoutKind.Seque ntial, CharSet:=CharSe t.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(Unma nagedType.LPTSt r)> 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(Marsha l.SystemDefault CharSize = 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(Marsha l.SystemDefault CharSize = 1, LVM_SETITEMA, LVM_SETITEMW))

Friend Const LVM_SETEXTENDED LISTVIEWSTYLE As Integer = LVM_FIRST + 54

Friend Const LVIF_IMAGE As Integer = &H2
Friend Const LVS_EX_SUBITEMI MAGES As Integer = &H2

Friend Shared Function ListView_GetIte m(ByVal hwnd As IntPtr, ByRef lvi As
Win32.Native.LV ITEM) As Boolean
Return CBool(Win32.Nat ive.SendMessage (hwnd, Win32.Native.LV M_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.LV ITEM) 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_SetSub ItemImageIndex( 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_SetIte m(hwnd, lvi)
End Sub

Friend Shared Function ListView_GetSub ItemImageIndex( 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_GetIte m(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(myL istView.Handle, LVM_SETEXTENDED LISTVIEWSTYLE,
LVS_EX_SUBITEMI MAGES, LVS_EX_SUBITEMI MAGES)
/claes

"Adam Honek" <Ad*******@Webm aster2001.frees erve.co.uk> wrote in message
news:eN******** ******@TK2MSFTN GP02.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 = ReadINIFileValu e(INI_SECTION_T YPE1 + " " + CType(iCounter,
String), "Program name", MyAccountsINIFi lePath)

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_SetSub ItemImageIndex( ) after adding the subitem
to the LV as normal?

Thanks,
Adam

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

<StructLayout(L ayoutKind.Seque ntial, CharSet:=CharSe t.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(Unma nagedType.LPTSt r)> 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(Marsha l.SystemDefault CharSize = 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(Marsha l.SystemDefault CharSize = 1, LVM_SETITEMA, LVM_SETITEMW))

Friend Const LVM_SETEXTENDED LISTVIEWSTYLE As Integer = LVM_FIRST + 54

Friend Const LVIF_IMAGE As Integer = &H2
Friend Const LVS_EX_SUBITEMI MAGES As Integer = &H2

Friend Shared Function ListView_GetIte m(ByVal hwnd As IntPtr, ByRef lvi As
Win32.Native.LV ITEM) As Boolean
Return CBool(Win32.Nat ive.SendMessage (hwnd, Win32.Native.LV M_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.LV ITEM) 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_SetSub ItemImageIndex( 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_SetIte m(hwnd, lvi)
End Sub

Friend Shared Function ListView_GetSub ItemImageIndex( 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_GetIte m(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(myL istView.Handle, LVM_SETEXTENDED LISTVIEWSTYLE,
LVS_EX_SUBITEMI MAGES, LVS_EX_SUBITEMI MAGES)
/claes

"Adam Honek" <Ad*******@Webm aster2001.frees erve.co.uk> wrote in message
news:eN******** ******@TK2MSFTN GP02.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 = ReadINIFileValu e(INI_SECTION_T YPE1 + " " + CType(iCounter,
String), "Program name", MyAccountsINIFi lePath)

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 .NetCompactFram ework.

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 (.NetCompactFra mework) But was stuck with a few
errors…Can anybody help me out??
A few features like <marshal as> are not available in the
..NetCompactFra meWork.
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.Hand le is not available in .NetcompactFram ework
Class WinAPI

Public Declare Function SetCapture Lib "coredll.dl l" (ByVal hWnd As
IntPtr) As IntPtr
Public Declare Function GetCapture Lib "coredll.dl l" () 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(hOld Wnd)
Return hWnd

End Function

End Class
----------------------------------------------------------------------------------------------
Public Class Form1
Inherits System.Windows. Forms.Form
Friend WithEvents MainMenu1 As System.Windows. Forms.MainMenu

'<StructLayout( LayoutKind.Sequ ential, CharSet:=CharSe t.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(Unm anagedType.LPTS tr)>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(Marsha l.SystemDefault CharSize = 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(Marsha l.SystemDefault CharSize = 1, LVM_SETITEMA, LVM_SETITEMW))

Friend Const LVM_SETEXTENDED LISTVIEWSTYLE As Integer = LVM_FIRST + 54

Friend Const LVIF_IMAGE As Integer = &H2
Friend Const LVS_EX_SUBITEMI MAGES As Integer = &H2
Friend Shared Function ListView_GetIte m(ByVal hwnd As IntPtr, ByRef lvi
As LVITEM) As Boolean
Return CBool(SendMessa ge(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_SetSub ItemImageIndex( 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_GetIte m(hwnd, lvi)
End Sub

Friend Shared Function ListView_GetSub ItemImageIndex( 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_GetIte m(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.
InitializeCompo nent()

'Add any initialization after the InitializeCompo nent() 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.Loca tion = New Point(0, 0)
MyListView.View = View.Details
MyListView.Smal lImageList = Img

Dim ListItem1 As New ListViewItem
ListItem1.Image Index = 0

'How to define a subitem to be used in the call to
'ListView_GetSu bItemImageIndex
'Dim ListSubItem1 As New ListViewItem.Li stViewSubItem
'ListSubItem1.

‘Holds the handle to myListView
Dim hMyListView As IntPtr = WinAPI.GetHWnd( MyListView)

'SendMessage(My ListView.Handle , LVM_SETEXTENDED LISTVIEWSTYLE, _
'LVS_EX_SUBITEM IMAGES, LVS_EX_SUBITEMI MAGES)

'MyListView.Han dle is not available, so had to use a userdefined function to
obtain its handle...

SendMessage(hMy ListView, LVM_SETEXTENDED LISTVIEWSTYLE, _
LVS_EX_SUBITEMI MAGES, LVS_EX_SUBITEMI MAGES)

ListView_SetSub ItemImageIndex( hMyListView, 0, 0, 0)

MyListView.Visi ble = 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 InitializeCompo nent()
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.Missing MethodException ' occurred in
ListView2.exe

Exception 2: ListView_GetIte m()
An unhandled exception of type 'System.NotSupp ortedException' occurred in
ListView2.exe
How can I use SendMessage() in the vb.net on .net compactFramewor k??
How to make a call to ListView_SetSub ItemImageIndex( ) 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(L ayoutKind.Seque ntial, CharSet:=CharSe t.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(Unma nagedType.LPTSt r)> 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(Marsha l.SystemDefault CharSize = 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(Marsha l.SystemDefault CharSize = 1, LVM_SETITEMA, LVM_SETITEMW))

Friend Const LVM_SETEXTENDED LISTVIEWSTYLE As Integer = LVM_FIRST + 54

Friend Const LVIF_IMAGE As Integer = &H2
Friend Const LVS_EX_SUBITEMI MAGES As Integer = &H2

Friend Shared Function ListView_GetIte m(ByVal hwnd As IntPtr, ByRef lvi As
Win32.Native.LV ITEM) As Boolean
Return CBool(Win32.Nat ive.SendMessage (hwnd, Win32.Native.LV M_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.LV ITEM) 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_SetSub ItemImageIndex( 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_SetIte m(hwnd, lvi)
End Sub

Friend Shared Function ListView_GetSub ItemImageIndex( 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_GetIte m(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(myL istView.Handle, LVM_SETEXTENDED LISTVIEWSTYLE,
LVS_EX_SUBITEMI MAGES, LVS_EX_SUBITEMI MAGES)
/claes

"Adam Honek" <Ad*******@Webm aster2001.frees erve.co.uk> wrote in message
news:eN******** ******@TK2MSFTN GP02.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 = ReadINIFileValu e(INI_SECTION_T YPE1 + " " + CType(iCounter,
String), "Program name", MyAccountsINIFi lePath)

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 .NetCompactFram ework…
I get the error message
“ The Targeted version of the .NetCompactFram ework 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.Missing MethodException ' 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(L ayoutKind.Seque ntial, CharSet:=CharSe t.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(Unma nagedType.LPTSt r)> 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(Marsha l.SystemDefault CharSize = 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(Marsha l.SystemDefault CharSize = 1, LVM_SETITEMA, LVM_SETITEMW))

Friend Const LVM_SETEXTENDED LISTVIEWSTYLE As Integer = LVM_FIRST + 54

Friend Const LVIF_IMAGE As Integer = &H2
Friend Const LVS_EX_SUBITEMI MAGES As Integer = &H2

Friend Shared Function ListView_GetIte m(ByVal hwnd As IntPtr, ByRef lvi As
Win32.Native.LV ITEM) As Boolean
Return CBool(Win32.Nat ive.SendMessage (hwnd, Win32.Native.LV M_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.LV ITEM) 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_SetSub ItemImageIndex( 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_SetIte m(hwnd, lvi)
End Sub

Friend Shared Function ListView_GetSub ItemImageIndex( 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_GetIte m(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(myL istView.Handle, LVM_SETEXTENDED LISTVIEWSTYLE,
LVS_EX_SUBITEMI MAGES, LVS_EX_SUBITEMI MAGES)
/claes

"Adam Honek" <Ad*******@Webm aster2001.frees erve.co.uk> wrote in message
news:eN******** ******@TK2MSFTN GP02.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 = ReadINIFileValu e(INI_SECTION_T YPE1 + " " + CType(iCounter,
String), "Program name", MyAccountsINIFi lePath)

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

"LProgramme r" <LP*********@di scussions.micro soft.com> wrote in message
news:DC******** *************** ***********@mic rosoft.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 .NetCompactFram ework.
I get the error message
" The Targeted version of the .NetCompactFram ework 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.Missing MethodException ' 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(L ayoutKind.Seque ntial, CharSet:=CharSe t.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(Unma nagedType.LPTSt r)> 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(Marsha l.SystemDefault CharSize = 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(Marsha l.SystemDefault CharSize = 1, LVM_SETITEMA, LVM_SETITEMW))

Friend Const LVM_SETEXTENDED LISTVIEWSTYLE As Integer = LVM_FIRST + 54

Friend Const LVIF_IMAGE As Integer = &H2
Friend Const LVS_EX_SUBITEMI MAGES As Integer = &H2

Friend Shared Function ListView_GetIte m(ByVal hwnd As IntPtr, ByRef lvi
As
Win32.Native.LV ITEM) As Boolean
Return CBool(Win32.Nat ive.SendMessage (hwnd, Win32.Native.LV M_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.LV ITEM) 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_SetSub ItemImageIndex( 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_SetIte m(hwnd, lvi)
End Sub

Friend Shared Function ListView_GetSub ItemImageIndex( 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_GetIte m(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(myL istView.Handle, LVM_SETEXTENDED LISTVIEWSTYLE,
LVS_EX_SUBITEMI MAGES, LVS_EX_SUBITEMI MAGES)
/claes

"Adam Honek" <Ad*******@Webm aster2001.frees erve.co.uk> wrote in message
news:eN******** ******@TK2MSFTN GP02.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 = ReadINIFileValu e(INI_SECTION_T YPE1 + " " + CType(iCounter,
> String), "Program name", MyAccountsINIFi lePath)
>
> lvItem.SubItems .Add(sData) <-------- Cannot add image index here
>
>


Apr 20 '06 #10

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

Similar topics

2
21260
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
1362
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... "Specified argument was out of the range of valid values. Parameter Name: '9' is not a valid value for 'index'." ....when I attempt to "Refresh" a ListView control AFTER it has been sorted.
3
2814
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() { listView.View = View.Details; ArrayList LVcolTitles= new ArrayList(); LVcolTitles.Add("Drive"); LVcolTitles.Add("Cust");
0
2562
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 ListView.Columns.RemoveAt() then the ListView still displays fine. However, if I grab a subitem value via listView.Items.SubItems.Text Then I get the Text of the wrong column.
0
1444
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... "Specified argument was out of the range of valid values. Parameter Name: '9' is not a valid value for 'index'." ....when I attempt to "Refresh" a ListView control AFTER it has been sorted.
1
5679
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 is my code, but icon is not apperead with that code. Source code
6
5038
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 this possible? I intend on replacing an ActiveX grid with a listview control from a VB6 application that I've upgraded to VB .NET. The existing functionlality uses the mouseover event of the grid to display specific information within...
2
2636
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 seems so dependent on the image being the "anchor" of each row that I don't understand how to modify it. Thanks. Dim lv As ListView lv = Me.ListView1
11
9998
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 components ?
0
9353
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10123
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9975
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9909
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9788
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8794
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7342
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6623
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
3
3481
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.