Discussion:
Problem with Treeview control
(too old to reply)
Rakesh
2007-07-02 15:00:05 UTC
Permalink
Raw Message
Hi,

I am using a treeview control to show image on each node depending on a
particular variable's value (green if it is set and red if not. Bydefault red)

When I am setting the variable for a particular node then the node's image
is changed to green(required behavior). But when I click on a node which has
green image, the node's image is automatically changing to red and again
changing back to green after changing the node selection.

Please help me in solving this problem.

Thanks:
Rakesh
Sylvain
2007-07-02 17:43:27 UTC
Permalink
Raw Message
Post by Rakesh
When I am setting the variable for a particular node then the node's image
is changed to green(required behavior). But when I click on a node which has
green image, the node's image is automatically changing to red and again
changing back to green after changing the node selection.
because the index order for the red image is green index + 1
and because we don't initialise the iSelectedImage member of the
TVINSERTSTRUCT.

when selected image is not set, while default image is, the tree view
uses the image index (iImage + 1) when an item is selected.

-> add TVIF_SELECTEDIMAGE to the 'mask' field
init 'iSelectedImage' with same value than 'iImage'.

Sylvain.
Rakesh
2007-07-03 07:22:00 UTC
Permalink
Raw Message
First I thank you for your response.
But the default image is Red with index '0' and index of red image is '1'.
And the second thing is I am using C# language. Does TVIF_SELECTEDIMAGE
available in C#. If not please let me know what needs to be used in C#.

-Rakesh
Post by Sylvain
Post by Rakesh
When I am setting the variable for a particular node then the node's image
is changed to green(required behavior). But when I click on a node which has
green image, the node's image is automatically changing to red and again
changing back to green after changing the node selection.
because the index order for the red image is green index + 1
and because we don't initialise the iSelectedImage member of the
TVINSERTSTRUCT.
when selected image is not set, while default image is, the tree view
uses the image index (iImage + 1) when an item is selected.
-> add TVIF_SELECTEDIMAGE to the 'mask' field
init 'iSelectedImage' with same value than 'iImage'.
Sylvain.
Sylvain
2007-07-03 22:02:16 UTC
Permalink
Raw Message
Post by Rakesh
Post by Sylvain
Post by Rakesh
When I am setting the variable for a particular node then the node's image
is changed to green(required behavior). But when I click on a node which has
green image, the node's image is automatically changing to red and again
changing back to green after changing the node selection.
because the index order for the red image is green index + 1
and because we don't initialise the iSelectedImage member of the
TVINSERTSTRUCT.
when selected image is not set, while default image is, the tree view
uses the image index (iImage + 1) when an item is selected.
-> add TVIF_SELECTEDIMAGE to the 'mask' field
init 'iSelectedImage' with same value than 'iImage'.
First I thank you for your response.
But the default image is Red with index '0' and index of red image is '1'.
And the second thing is I am using C# language. Does TVIF_SELECTEDIMAGE
available in C#. If not please let me know what needs to be used in C#.
C# only adds (confusion, verbose stmts, ..., and) a property / method
paradigm over Win32 structure, we will so perform exactly the same thing
with different words, suck as:

TreeNode newNode = new TreeNode("a label");
newNode.ImageIndex = 0;
newNode.SelectedImageIndex = 0;
theTreeView.SelectedNode.Nodes.Add(newNode);

Sylvain.
Rakesh
2007-07-06 14:22:03 UTC
Permalink
Raw Message
Thnaks Sylvain,

Can you help me solving one more problem?
I want to retain the back color of the selected node when I change the
selection of the node through my form's next/previous buttons. To be clear
when I am clicking on any node with mouse the backcolor is turning to
blue(system generated). But when I am changing the selection, the backcolor
of the newly selected node is turning to white.
I tried to modify the backcolor explicitly but I am not getting the same
color as if system is giving by default.

thanks in advance,
Rakesh.
Sylvain
2007-07-06 21:14:24 UTC
Permalink
Raw Message
Post by Rakesh
Thnaks Sylvain,
Can you help me solving one more problem?
I want to retain the back color of the selected node when I change the
selection of the node through my form's next/previous buttons. To be clear
when I am clicking on any node with mouse the backcolor is turning to
blue(system generated). But when I am changing the selection, the backcolor
of the newly selected node is turning to white.
I tried to modify the backcolor explicitly but I am not getting the same
color as if system is giving by default.
not sure to understand exactly your problem.
but, when you click an item or another, the list has the focus so
selected item is highlighted; when you click on your next/prev buttons
these buttons have the focus and the list losing its focus draw selected
item w/o evidence of selection ... unless you add LVS_SHOWSELALWAYS to
the list's style, doing that will prevent the selected item to be drawn
on white background; to go ahead and to use the same bg color when the
list has focus or not you will need to use custom draw list (owner draw
list or normal list with handling of WM_DRAWITEM message).

Sylvain.
Ashish Agarwal
2011-08-23 06:24:04 UTC
Permalink
Raw Message
Can you please post the same code using win32. I am developing tree view using win32 and for each node type i want to show different bitmap image. e.g. for folder type folder bitmap, txt file text bitmap,etc.

Sample code:
HIMAGELIST hImageList = ImageList_Create(16, 16, ILC_COLOR16, 2, 10);

HBITMAP hBitMap = LoadBitmap(GetModuleHandle("my.dll"), MAKEINTRESOURCE(IDB_TREE_IMAGES)); HBITMAP hBitMap1 = LoadBitmap(GetModuleHandle("my.dll"), MAKEINTRESOURCE(IDB_BITMAP3));
HBITMAP hBitMap2 = LoadBitmap(GetModuleHandle("my.dll"), MAKEINTRESOURCE(IDB_BITMAP2));

ImageList_Add(hImageList, hBitMap, NULL); ImageList_Add(hImageList, hBitMap1, NULL); ImageList_Add(hImageList, hBitMap2, NULL); DeleteObject(hBitMap); DeleteObject(hBitMap1); DeleteObject(hBitMap2);
TreeView_SetImageList(hTree, hImageList, TVSIL_NORMAL);


Now when I create a node i want to change or get accessor to hImageList to point to 2nd bitmap.
Post by Rakesh
Hi,
I am using a treeview control to show image on each node depending on a
particular variable's value (green if it is set and red if not. Bydefault red)
When I am setting the variable for a particular node then the node's image
is changed to green(required behavior). But when I click on a node which has
green image, the node's image is automatically changing to red and again
changing back to green after changing the node selection.
Please help me in solving this problem.
Rakesh
Post by Sylvain
because the index order for the red image is green index + 1
and because we don't initialise the iSelectedImage member of the
TVINSERTSTRUCT.
when selected image is not set, while default image is, the tree view
uses the image index (iImage + 1) when an item is selected.
-> add TVIF_SELECTEDIMAGE to the 'mask' field
init 'iSelectedImage' with same value than 'iImage'.
Sylvain.
Post by Rakesh
First I thank you for your response.
But the default image is Red with index '0' and index of red image is '1'.
And the second thing is I am using C# language. Does TVIF_SELECTEDIMAGE
available in C#. If not please let me know what needs to be used in C#.
-Rakesh
Post by Rakesh
Post by Rakesh
Post by Sylvain
Post by Rakesh
When I am setting the variable for a particular node then the
node's image
Post by Rakesh
Post by Sylvain
Post by Rakesh
is changed to green(required behavior). But when I click on a node
which has
Post by Rakesh
Post by Sylvain
Post by Rakesh
green image, the node's image is automatically changing to red and
again
Post by Rakesh
Post by Sylvain
Post by Rakesh
changing back to green after changing the node selection.
because the index order for the red image is green index + 1
and because we don't initialise the iSelectedImage member of the
TVINSERTSTRUCT.
when selected image is not set, while default image is, the tree view
uses the image index (iImage + 1) when an item is selected.
-> add TVIF_SELECTEDIMAGE to the 'mask' field
init 'iSelectedImage' with same value than 'iImage'.
C# only adds (confusion, verbose stmts, ..., and) a property / method
paradigm over Win32 structure, we will so perform exactly the same thing
TreeNode newNode = new TreeNode("a label");
newNode.ImageIndex = 0;
newNode.SelectedImageIndex = 0;
theTreeView.SelectedNode.Nodes.Add(newNode);
Sylvain.
Post by Rakesh
Thnaks Sylvain,
Can you help me solving one more problem?
I want to retain the back color of the selected node when I change the
selection of the node through my form's next/previous buttons. To be clear
when I am clicking on any node with mouse the backcolor is turning to
blue(system generated). But when I am changing the selection, the backcolor
of the newly selected node is turning to white.
I tried to modify the backcolor explicitly but I am not getting the same
color as if system is giving by default.
thanks in advance,
Rakesh.
Post by Sylvain
not sure to understand exactly your problem.
but, when you click an item or another, the list has the focus so
selected item is highlighted; when you click on your next/prev buttons
these buttons have the focus and the list losing its focus draw selected
item w/o evidence of selection ... unless you add LVS_SHOWSELALWAYS to
the list's style, doing that will prevent the selected item to be drawn
on white background; to go ahead and to use the same bg color when the
list has focus or not you will need to use custom draw list (owner draw
list or normal list with handling of WM_DRAWITEM message).
Sylvain.
Loading...