By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,837 Members | 1,222 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,837 IT Pros & Developers. It's quick & easy.

ListView images in header (sort indicator) -- converted code from vb6 not working

P: n/a

I'm trying to put icons in the header of my ListView. All the .net
posts I found refer to an example on thecodeproject which is no longer
there (part of commercial package now).

I converted the code I used in VB6 which all appears to run ok but
doesn't actually create the images ever. These are generic functions
to set the images for any listview.

Please help,

Thanks,

Sam
' Win32 is a custom class that has the necessary Win32 constants,
structures, and function declarations

Public Sub ListViewSetHeaderImages(ByVal lvw As ListView, ByVal
images As ImageList)
Dim headerHandle As IntPtr = Win32.SendMessage(lvw.Handle,
Win32.LVM_GETHEADER, IntPtr.Zero, IntPtr.Zero)
Win32.SendMessage(headerHandle, Win32.HDM_SETIMAGELIST,
IntPtr.Zero, images.Handle)
End Sub

Public Sub ListViewSetHeaderIcon(ByVal lvw As ListView, ByVal
headerText As String, ByVal columnIndex As Integer, ByVal imageIndex
As Integer)

Dim headerHandle As IntPtr
Dim HD As New Win32.HDITEM

headerHandle = Win32.SendMessage(lvw.Handle,
Win32.LVM_GETHEADER, IntPtr.Zero, IntPtr.Zero)

With HD
.mask = Win32.HDI_IMAGE Or Win32.HDI_FORMAT
.pszText = headerText
.fmt = Win32.HDF_STRING Or Win32.HDF_IMAGE Or
Win32.HDF_BITMAP_ON_RIGHT
.iImage = imageIndex
End With

Win32.SendMessage(headerHandle, Win32.HDM_SETITEM, columnIndex,
HD)

End Sub

Private Sub ListViewRemoveHeaderIcon(ByVal lvw As ListView, ByVal
columnIndex As Integer)
Dim headerHandle As IntPtr
Dim hdHeader As New Win32.HDITEM

headerHandle = Win32.SendMessage(lvw.Handle,
Win32.LVM_GETHEADER, IntPtr.Zero, IntPtr.Zero)

hdHeader.mask = Win32.HDI_FORMAT
hdHeader.fmt = hdHeader.fmt Or Win32.HDF_STRING
Win32.SendMessage(headerHandle, Win32.HDM_SETITEM, columnIndex,
hdHeader)

End Sub

Nov 21 '05 #1
Share this Question
Share on Google+
6 Replies


P: n/a
"Samuel R. Neff" <sr********@spampleasespeakeasy.net> schrieb:
I'm trying to put icons in the header of my ListView. All the .net
posts I found refer to an example on thecodeproject which is no longer
there (part of commercial package now).


Customizing the header control in a ListView
<URL:http://www.codeproject.com/cs/miscctrl/customheader.asp>

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>
Nov 21 '05 #2

P: n/a
"Samuel R. Neff" <sr********@spampleasespeakeasy.net> schrieb:
I'm trying to put icons in the header of my ListView. All the .net
posts I found refer to an example on thecodeproject which is no longer
there (part of commercial package now).


Customizing the header control in a ListView
<URL:http://www.codeproject.com/cs/miscctrl/customheader.asp>

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>
Nov 21 '05 #3

P: n/a

That example does a lot more than just put images in the headers. It
takes over creation and drawing of the columns and seems to have a lot
more overhead than is necessary for the task (it does more than what I
and most people asking the question want). I'm looking for something
much smaller.

Really, the VB6 converted code I posted should work--I'm not sure why
it doesn't. It's just SendMessage calls.

Sam
On Tue, 7 Dec 2004 19:08:06 +0100, "Herfried K. Wagner [MVP]"
<hi***************@gmx.at> wrote:
"Samuel R. Neff" <sr********@spampleasespeakeasy.net> schrieb:
I'm trying to put icons in the header of my ListView. All the .net
posts I found refer to an example on thecodeproject which is no longer
there (part of commercial package now).


Customizing the header control in a ListView
<URL:http://www.codeproject.com/cs/miscctrl/customheader.asp>


Nov 21 '05 #4

P: n/a

That example does a lot more than just put images in the headers. It
takes over creation and drawing of the columns and seems to have a lot
more overhead than is necessary for the task (it does more than what I
and most people asking the question want). I'm looking for something
much smaller.

Really, the VB6 converted code I posted should work--I'm not sure why
it doesn't. It's just SendMessage calls.

Sam
On Tue, 7 Dec 2004 19:08:06 +0100, "Herfried K. Wagner [MVP]"
<hi***************@gmx.at> wrote:
"Samuel R. Neff" <sr********@spampleasespeakeasy.net> schrieb:
I'm trying to put icons in the header of my ListView. All the .net
posts I found refer to an example on thecodeproject which is no longer
there (part of commercial package now).


Customizing the header control in a ListView
<URL:http://www.codeproject.com/cs/miscctrl/customheader.asp>


Nov 21 '05 #5

P: n/a
Found the problem. The functions I posted actually do work as
intended--as only as the Win32 declarations are correct. :-)

I had copied the Win32 declarations from the other project posted,
after automatically converting from C# to VB.NET. The converter
reorded the members alphabetically including the structure members
(which is really bad sine they were even marked as sequential). After
I recreated the Win32 type declaration for HDITEM the helper functions
for setting the image worked fine.

Sam

Nov 21 '05 #6

P: n/a
Found the problem. The functions I posted actually do work as
intended--as only as the Win32 declarations are correct. :-)

I had copied the Win32 declarations from the other project posted,
after automatically converting from C# to VB.NET. The converter
reorded the members alphabetically including the structure members
(which is really bad sine they were even marked as sequential). After
I recreated the Win32 type declaration for HDITEM the helper functions
for setting the image worked fine.

Sam

Nov 21 '05 #7

This discussion thread is closed

Replies have been disabled for this discussion.