Re: Showing two images on a treenode

Tech-Archive recommends: Fix windows errors by optimizing your registry



You can use a state image as the second image (I assume you use the normal
ImageIndex for the first one). Unfortunately 1.1 doesn't expose any
properties to handle state images but some P/Invoke stuff will handle that
problem. Also note that this method won't work if you're using checkboxes in
your treeview. Here's some code that should help. It's in VB though so
you'll have to translate it

<StructLayout(LayoutKind.Sequential)> Friend Structure TVITEM
Friend mask As Integer
Friend hItem As IntPtr
Friend state As Integer
Friend stateMask As Integer
<MarshalAs(UnmanagedType.LPTStr)> Friend lpszText As String
Friend cchTextMax As Integer
Friend iImage As Integer
Friend iSelectedImage As Integer
Friend cChildren As Integer
Friend lParam As IntPtr
End Structure

Friend Const TVIF_STATE As Integer = &H8
Friend Const TVIS_STATEIMAGEMASK As Integer = &HF000
Friend Const TVSIL_STATE As Integer = 2

Friend Const TV_FIRST As Integer = &H1100
Friend Const TVM_SETITEMA As Integer = TV_FIRST + 13
Friend Const TVM_SETITEMW As Integer = TV_FIRST + 63
Friend Const TVM_SETIMAGELIST As Integer = TV_FIRST + 9

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

Friend Shared Function INDEXTOSTATEIMAGEMASK(ByVal i As Integer) As Integer
Return (i << 12)
End Function

Friend Shared Sub TreeView_SetStateImageIndex(ByVal hwnd As IntPtr, ByVal
hItem As IntPtr, ByVal imageIndex As Integer)
Dim tvi As TVITEM
tvi.hItem = hItem
tvi.mask = TVIF_STATE
tvi.stateMask = TVIS_STATEIMAGEMASK
tvi.state = INDEXTOSTATEIMAGEMASK(imageIndex)
If (Marshal.DefaultCharSize = 1) Then
SendMessage(hwnd, TVM_SETITEMA, IntPtr.Zero, tvi)
Else
SendMessage(hwnd, TVM_SETITEMW, IntPtr.Zero, tvi)
End If
End Sub

Friend Shared Sub TreeView_SetStateImageList(ByVal hwnd As IntPtr, ByVal
hImageList As IntPtr)
SendMessage(hwnd, TVM_SETIMAGELIST , New IntPtr(TVSIL_STATE),
hImageList)
End Sub

Use like this:

Create an ImageList containing the images you want (you can use the same as
for your normal images) and then call TreeView_SetStateImageList like this:
TreeView_SetStateImageList(yourTreeView.Handle, yourImageList.Handle)
(You only need to call it once)

Once you've done that you can call TreeView_SetStateImageIndex when you want
to set the image to display for a TreeNode:
TreeView_SetStateImageIndex(yourTreeView.Handle, yourTreeNode.Handle,
yourIndex)


/claes



<gooseneckster@xxxxxxxxxxxxxx> wrote in message
news:1151505419.812342.312450@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
Hi,

Does anyone have an idea on how to display two images on a treeview's
treenode? (.Net v1.1)

At the moment I have made a TreeViewEx component that inherits from
TreeView.
I'm overriding the OnPaint and there I call method below with
PaintEventArgs.Graphics and my root TreeNode:

private void SetImagePositions(Graphics g, TreeNode node)
{
if (node.IsVisible)
{
node.ImageIndex = 0; // for test, assumes an ImageList with two
images is chosen for the treeview
node.SelectedImageIndex = 0;
PictureBox statusImage = new PictureBox();
statusImage.Image = ImageList.Images[1]; // for test, assumes an
ImageList with two images is chosen for the treeview
statusImage.Location = new Point(node.Bounds.Left-22,
node.Bounds.Top);
statusImage.Size = new Size(16, 16);
g.DrawImage(statusImage.Image, statusImage.Location);

foreach(TreeNode childNode in node.Nodes)
SetImagePositions(g, childNode);
}
}

This however works badly, as if this triggers some other event which
makes the treeview redraw some of it's nodes again on top of the extra
image...

Does anyone have any idea, please help...

Thanks alot in advance,
Cheers
Jag



.



Relevant Pages

  • Re: How do I enable friend to view my pictures (jpg) on cd on his TV
    ... I want to be able to see the pictures on my TV and enable my friend also to see them on his tv. ... I regret that I cannot find a solution or step by step instructions to finalise the DVD whatever that means. ... Note that if images are stored at the standard video resolution many DVD players are able to display, a LOT of pictures can be stored on a CD-R. ...
    (microsoft.public.word.drawing.graphics)
  • Re: {OT} Sixteen year old girl...
    ... >> Remember when I told you about my friend from college? ... > actively sought their victims if they had not seen images". ... he writes his documentation for the state. ...
    (alt.autos.toyota)
  • Re: saving images from a slid show?
    ... I don't know of any way to strip the images out of the wmv file. ... suggestion I could give is to ask your friend to send you soft copies of the ... >I have received a file from a friend of mine which has a wmv extension. ...
    (microsoft.public.windowsxp.photos)
  • Re: Red Xs appearing instead of images
    ... MS MVP - (IE/OE) ... > In visiting Friend A, she receives an email that appears to have ... It has text and animated images. ...
    (microsoft.public.windows.inetexplorer.ie6_outlookexpress)
  • Re: Listview SubItems image index
    ... Public Declare Function SetCapture Lib "coredll.dll" (ByVal hWnd As ... IntPtr) As IntPtr ... Friend Structure LVITEM ... Friend Shared Function ListView_GetItem(ByVal hwnd As IntPtr, ByRef lvi ...
    (microsoft.public.dotnet.languages.vb)