Page 1 of 1

Expand items using code

Posted: 06 Jan 2006, 15:36
by c.haarmeijer
Hi Timo,

I have selected an item that is also deep in the tree. I now want to expand the tree towards the newly selected item. Is there a function that does this ?

Kind regards,

Chris Haarmeijer

Posted: 06 Jan 2006, 17:19
by TiKu
Hi,

the EnsureVisible method should be what you're looking for.

Posted: 13 Jan 2006, 16:43
by Guest
Hi Timu,

It seems that I only have a function EnsureVisible that returns TRUE or FALSE, so a get property, not a set property. What did I do wrong ?

Chris

Posted: 13 Jan 2006, 19:48
by TiKu
The EnsureVisible method ensures that an item is visible, i. e. if it is not visible, it is scrolled into view and parent items are expanded just as necessary. The return value of this method tells you whether any item expansions took place in order to make the item visible.
Isn't that what you want? Maybe I misunderstood your question. If you want to simply set the expansion state of an item, take a look at its ExpansionState property and/or its Collapse and Expand methods.

TiKu

Posted: 16 Jan 2006, 08:34
by Guest
Hi Timo,

The problem is, I thought I could set the visibility using the EnsureVisible method, but I only have a function EnsureVisible that <returns> the visibility status, not one that I can use to <set> the visibility.

Kind regards,

Chris

Posted: 16 Jan 2006, 13:11
by TiKu
Ah, you want to hide items. Well, this is not possible.

Posted: 17 Jan 2006, 11:42
by Guest
:-)

No, no hiding. The thing I want is that when a user selects an item in a different control, I want to jump straight to that item in the treeview. EnsureVisible sounds right, but the problem is this:

inline VARIANT_BOOL ITreeViewItem::EnsureVisible ( ) {
VARIANT_BOOL _result = 0;
HRESULT _hr = raw_EnsureVisible(&_result);
if (FAILED(_hr)) _com_issue_errorex(_hr, this, __uuidof(this));
return _result;
}

A piece of code generated by the ocx. As you can see here, I cannot change the property of an item using the ensurevisible function. It is a <get> property, not a <set> property. I do not want to hide an item, but I want to jump straight to it (expands all parents until that item is reached). I can do this in a couple of lines of code, but in the original tree control of Windows, you can use the expand function to do this.

Sorry for the hassle and mixup in what I want to do.

Chris

Posted: 17 Jan 2006, 12:21
by TiKu
So you probably have not understood how EnsureVisible is working. You get the ITreeViewItem interface of the item for which you want to ensure visibility and call EnsureVisible on this item. EnsureVisible wraps the TVM_ENSUREVISIBLE message.
If you can't get it working, you may also use something like this:

Code: Select all

//pseudo code
SendMessage(hWndTvw, TVM_ENSUREVISIBLE, 0, LongToHandle(pTreeViewItem->get_Handle()));
HTH
TiKu

Posted: 17 Jan 2006, 14:21
by Guest
Ok, I will use the SendMessage method then. The problem still remains: I cannot invoke the EnsureVisible function. This function only returns a true or false value. This does allow me to set the visibility. For this, I need a EnsureVisible(true/false) function.

Kind regards,

Chris

Posted: 17 Jan 2006, 15:07
by TiKu
What do you want to pass to EnsureVisible? You don't pass any boolean value with TVM_ENSUREVISIBLE either. So what do you want to pass to the EnsureVisible method? :dontknow:
/edit: EnsureVisible is not a property, it is a method.

Posted: 18 Jan 2006, 07:35
by Guest
Argl! I was under the impression that EnsureVisible was a put/get method that acts like a property under COM. Stupid. Thanks!