CXTTreeBase::FindItem method usage |
Post Reply |
Author | |
MacW
Senior Member Joined: 26 June 2007 Status: Offline Points: 253 |
Post Options
Thanks(0)
Posted: 24 March 2008 at 7:07am |
This method can be used to find text in a CXTTreeBase control or derived class. But the method has a major flaw in my opinion, or I don't understand how to use it.
When you call FindItem for the first time, it will return the HTREEITEM if the item found (if any). An application then usually selects this item to show the user the found item. If you now want to implement the usual "Find Next" command, you're at a loss. The FindItem method can either take a 0 as the "start item" to search, or the HTREEITEM of the item you want to start your search. If you use 0, and the currently selected item is already a match (as in our case), the FindItem method will just return the same HTREEITEM. It will not search for the "next" match itself. In order to implement a "find next" command, we will have to identify the "next" item, and then call FindItem with the HTREEITEM of this "next" item. Identifying the "next" item in a tree control is not trivial, because it involves going up and down the hierarchy as needed (children, siblings, recursive up the parent hierarchy until a not yet visited item is found. Since we don't have the information which items have already been searched by the FindItem method, it will be much better if Codejock would implement the code internally, within the FindItem method. |
|
MacW
Senior Member Joined: 26 June 2007 Status: Offline Points: 253 |
Post Options
Thanks(0)
|
As a work-around:
You can implement the functionality using the GetNextItem and GetPrevItem methods of the CXTTreeBase class, by keeping track of the "last found" item somewhere else, and then using these methods as appropriate. |
|
Oleg
Admin Group Joined: 21 May 2003 Location: United States Status: Offline Points: 11234 |
Post Options
Thanks(0)
|
Hi,
Its not "work-around" it is designed way for such operation :-)
|
|
Oleg, Support Team
CODEJOCK SOFTWARE SOLUTIONS |
|
MacW
Senior Member Joined: 26 June 2007 Status: Offline Points: 253 |
Post Options
Thanks(0)
|
Hi,
I have a reproducible bug where calling FindItem with bDownDir = FALSE causes an endless loop within the FindItem method. The search never terminates and I need to force my application to close. My tree contains one node with the search text. I select this entry, and then call FindItem with the direction upwards. FindItem never finds the entry, but instead falls into a loop. |
|
Oleg
Admin Group Joined: 21 May 2003 Location: United States Status: Offline Points: 11234 |
Post Options
Thanks(0)
|
Hello,
Yes, seems there is bug if there are 2 or more root items. :(
Do you have one root item ?
|
|
Oleg, Support Team
CODEJOCK SOFTWARE SOLUTIONS |
|
mgampi
Senior Member Joined: 14 July 2003 Status: Offline Points: 1198 |
Post Options
Thanks(0)
|
Hi;
I use this part of code if I want to search for items in a tree. It works very well and I don't have troubles with find and or find next.
In my case I use find/find next with the same toolbar button:
void CPVBar::OnSearch(NMHDR* pNMHDR, LRESULT* pResult)
{ CString strFind = pMyControl_->GetEditText(); HTREEITEM hItem=0; if ((hItem=MyTree_.GetSelectedItem())==0) hItem=MyTree_.GetRootItem(); else hItem=MyTree_.GetNextItem(hItem); if ((hItem=MyTree_.FindItem(strFind, FALSE, TRUE, FALSE, hItem))!=0)
{ VERIFY(MyTree_.SelectItem(hItem)); MyTree_.EnsureVisible(hItem); MyTree_.SetItemBold(hItem); } *pResult = 1; // Handled; } } |
|
Martin
Product: Xtreme Toolkit v 19.0.0, new Projects v 19.1.0 Platform: Windows 10 v 1909 (64bit) Language: VC++ 2017 |
|
MacW
Senior Member Joined: 26 June 2007 Status: Offline Points: 253 |
Post Options
Thanks(0)
|
Yes, in this case. The contents of the tree are flexible, and there may be several root items.
|
|
MacW
Senior Member Joined: 26 June 2007 Status: Offline Points: 253 |
Post Options
Thanks(0)
|
Thanks for helping out
Unfortunately, it seems that your method does not find all possible matches when a sub-item is selected, and the sibling item above also has a sub-item which would cause a match, like in the attached screen shot. I start with the orange node, searching upwards for the sub-term "ba". . |
|
mgampi
Senior Member Joined: 14 July 2003 Status: Offline Points: 1198 |
Post Options
Thanks(0)
|
Hi;
In my case I only needed forward only search capabilities, but I think it's a good starting point for your requirements. Just call GetPrevItem() if a search with the start item got by GetNextItem() gives no result; voila!
|
|
Martin
Product: Xtreme Toolkit v 19.0.0, new Projects v 19.1.0 Platform: Windows 10 v 1909 (64bit) Language: VC++ 2017 |
|
Oleg
Admin Group Joined: 21 May 2003 Location: United States Status: Offline Points: 11234 |
Post Options
Thanks(0)
|
Him
Please replace GetLastItem method as
HTREEITEM CXTTreeBase::GetLastItem(HTREEITEM hItem) const { // Temporary used variable HTREEITEM htiNext; // Get the last item at the top level
if (hItem == NULL) { hItem = m_pTreeCtrl->GetRootItem(); htiNext = m_pTreeCtrl->GetNextSiblingItem(hItem);
while (htiNext != NULL) { hItem = htiNext; htiNext = m_pTreeCtrl->GetNextSiblingItem(htiNext); } } while (m_pTreeCtrl->ItemHasChildren(hItem) != NULL)
{ // Find the last child of hItem htiNext = m_pTreeCtrl->GetChildItem(hItem); while (htiNext != NULL) { hItem = htiNext; htiNext = m_pTreeCtrl->GetNextSiblingItem(htiNext); } } return hItem;
}
|
|
Oleg, Support Team
CODEJOCK SOFTWARE SOLUTIONS |
|
mgampi
Senior Member Joined: 14 July 2003 Status: Offline Points: 1198 |
Post Options
Thanks(0)
|
Hi Oleg;
will this fix also be applied in 12.0 final?
|
|
Martin
Product: Xtreme Toolkit v 19.0.0, new Projects v 19.1.0 Platform: Windows 10 v 1909 (64bit) Language: VC++ 2017 |
|
Oleg
Admin Group Joined: 21 May 2003 Location: United States Status: Offline Points: 11234 |
Post Options
Thanks(0)
|
Hi,
Yes.
|
|
Oleg, Support Team
CODEJOCK SOFTWARE SOLUTIONS |
|
MacW
Senior Member Joined: 26 June 2007 Status: Offline Points: 253 |
Post Options
Thanks(0)
|
Hi, Oleg
this fix seems to have solved the problem. I made some initial tests and it looks good |
|
Post Reply | |
Tweet
|
Forum Jump | Forum Permissions You cannot post new topics in this forum You cannot reply to topics in this forum You cannot delete your posts in this forum You cannot edit your posts in this forum You cannot create polls in this forum You cannot vote in polls in this forum |