Hi guys,

I have a small problem... i want to unselect a item in a treeview with multiple selection, using the small code snippet below

mov myItem.hItem, esi
mov myItem.state, 0 ; unselect
mov myItem.stateMask, 1 ; bit 1 is the bit specifying SELECTION
lea eax, myItem
mov dword ptr , TVIF_STATE
push eax
push 0
push 0110Dh ; TVM_SETITEM
push dword ptr
call SendMessageA
cmp eax, -1


However it doesnt seem to help, the item still remain selected... also MSDN says that "Returns zero if successful or -1 otherwise." but the return in eax i always get is 1????

What am i doing wrong here?

Thanx,
crUsAdEr
Posted on 2002-11-13 13:10:22 by crusader
Im not sure about myItem.stateMask, but I am almost positive you need to fill
in myItem.mask to TVIF_STATE first.


mask

Array of flags that indicate which of the other structure members contain valid data or which are to be filled in. This member can be a combination of the following values:

Value Meaning
TVIF_CHILDREN The cChildren member is valid.
TVIF_IMAGE The iImage member is valid.
TVIF_PARAM The lParam member is valid.
TVIF_SELECTEDIMAGE The iSelectedImage member is valid.
TVIF_STATE The state and stateMask members are valid.
TVIF_TEXT The pszText and cchTextMax members are valid.
Posted on 2002-11-13 14:49:08 by Graebel
Hi Graebel,

Yep, thanx for the info... i have already done so in my code above...
+++++++++++++++++++++++++++++
lea eax, myItem
mov dword ptr , TVIF_STATE
+++++++++++++++++++++++++++++

moving directly like this
mov myItem.mask, TVIF_STATE
gives me error about wrong operand??? so i got my way round by doing as above.. since State is the first dword in TV_ITEM structure... still doesnt wor somehow...

Thanks, hope my question is not too confusing, i dont know how else to explain myself...
crUsAdEr
Posted on 2002-11-13 17:13:38 by crusader
From what I see in your code, I don't know
what is in esi, tell me what hat value is of.

it should be the item in the treeview list
that you want unselected.


Zcoder.....
Posted on 2002-11-13 20:45:49 by Zcoder
Hi ZCoder,

esi is the handle to the item surely... i have used it in the code section right before it to obtain the text of the item so it would not be wrong...

Thanx anyway...
crUsAdEr
Posted on 2002-11-13 21:00:46 by crusader
moving directly like this
mov myItem.mask, TVIF_STATE
gives me error about wrong operand???
mask is reserved word.
mov myItem.imask, TVIF_STATE

To unselect use this code:
invoke SendMessage, hwndTreeView, TVM_SELECTITEM, TVGN_CARET, NULL

If last parameter is NULL, the selection is removed from the currently selected item, if any.
Posted on 2002-11-14 06:01:44 by Four-F
The message TVM_SELECTITEM is the following
TV_SELECTITEM
wParam = (WPARAM) flag;
lParam = (LPARAM) (HTREEITEM) hitem;


Parameters

flag

Action flag. This parameter can be one of the following values:

Value Meaning
TVGN_CARET Sets the selection to the given item.
TVGN_DROPHILITE Redraws the given item in the style used to indicate the target of a drag and drop operation.
TVGN_FIRSTVISIBLE Scrolls the tree view vertically so that the given item is the first visible item.


hitem

Handle to an item. If hitem is NULL, the selection is removed from the currently selected item, if any.


So therefore i see a bug in your snipplet. You should push 0 before push eax and not the other way round.


mov myItem.hItem, esi
mov myItem.state, 0 ; unselect
mov myItem.stateMask, 1 ; bit 1 is the bit specifying SELECTION
lea eax, myItem
mov dword ptr [eax], TVIF_STATE
push 0
push eax
push 0110Dh ; TVM_SETITEM
push dword ptr [edi+02D0h]
call SendMessageA
Posted on 2002-11-14 06:02:39 by roticv
Hi guys,

Thanx a lot for the response.. guess i have been doing it wrongly.. just another question..

+++++++++++++++++++++++++++++++++
invoke SendMessage, hwndTreeView, TVM_SELECTITEM, TVGN_CARET, NULL

If last parameter is NULL, the selection is removed from the currently selected item, if any.
++++++++++++++++++++++++++++++++++

When i used the above command, a random Item get deselected or no item get deselected at all among many selected items... however when i used this

===============================
invoke SendMessage, hwndTreeView, TVM_SELECTITEM, TVGN_CARET, esi
invoke SendMessage, hwndTreeView, TVM_SELECTITEM, TVGN_CARET, NULL
===============================

then the item in esi get de-selected fine... :confused: .. with the above ocde it works fine but i just want to know the reason behind it...

Thanx
crUsAdEr
Posted on 2002-11-14 11:38:41 by crusader