Iterating a ITreeViewItems collection

The place for threads about version 2.x of TimoSoft ExplorerTreeView.
Post Reply
Guest

Iterating a ITreeViewItems collection

Post by Guest » 18 Jan 2006, 07:51

Hi Timo,

I have a selection of items in a ITreeViewItems class. I would like to iterate over this selection using a for loop until Count(). I see you have an Items() function that should do the job, but I do not know what to pass as parameter for the itemIdentifierType. I tried iitID, that does not seem to work and iitHandle expects a valid item handle....

Kind regards,

Chris

User avatar
TiKu
Administrator
Administrator
Posts: 832
Joined: 28 Sep 2004, 21:10
Location: Unterföhring
Contact:

Post by TiKu » 18 Jan 2006, 13:16

In VB you use a For-Each loop:

Code: Select all

Dim ti As TreeViewItem

For Each ti In ExTvw.TreeItems
  ' do something with ti
Next ti
C++ doesn't have such a construct, but you can do what For Each is doing behind the scences:

Code: Select all

// pTvwItems is a ITreeViewItems*
IEnumVARIANT* pEnumerator;
pTvwItems->QueryInterface(IID_IEnumVARIANT, reinterpret_cast<void**>(&pEnumerator));
if(pEnumerator) {
	VARIANT item;
	VariantInit(&item);
	ULONG dummy = 0;
	while(pEnumerator->Next(1, &item, &dummy) == S_OK) {
		if((item.vt == VT_DISPATCH) && item.pdispVal) {
			ITreeViewItem* pTvwItem;
			item.pdispVal->QueryInterface(IID_ITreeViewItem, reinterpret_cast<void**>(&pTvwItem));
			if(pTvwItem) {
				// do something with pTvwItem
				pTvwItem->Release();
			}
		}
		VariantClear(&item);
	}
	pEnumerator->Release();
}
HTH
TiKu
Crunching for Fab36_Folding-Division at Folding@Home. Join Fab36/Fab30! - Folding@Home and BOINC
Boycott DRM! Boycott HDCP!

Post Reply