wxTreeCtrl SelectItem selects but doesn't highlight the item
wxTreeCtrl SelectItem selects but doesn't highlight the item
Hello,
I wrote a program that moves items between different tree nodes. I select an item in the tree, push a button and it moves it to another node. After this, I use SelectItem() to select the next time in the list.
This selection process is working correctly in the background, as I can access the data and everything associated with the newly selected item (so I can keep clicking the "move" button and moving subsequent items), but SelectItem is not highlighting the item, even though it IS selected.
Is there a "Highlight(wxTreeItemId)" function or anything to update the GUI? MyWxTreeCtrl->Update() doesn't work.
Thanks!
Jack
I wrote a program that moves items between different tree nodes. I select an item in the tree, push a button and it moves it to another node. After this, I use SelectItem() to select the next time in the list.
This selection process is working correctly in the background, as I can access the data and everything associated with the newly selected item (so I can keep clicking the "move" button and moving subsequent items), but SelectItem is not highlighting the item, even though it IS selected.
Is there a "Highlight(wxTreeItemId)" function or anything to update the GUI? MyWxTreeCtrl->Update() doesn't work.
Thanks!
Jack
This might be what you are looking for,
-Max
The selection should be highlighted for you.http://www.wxwidgets.org/manuals/stable/wx_wxtextctrl.html#wxtextctrlsetselection wrote:wxTextCtrl::SetSelection
virtual void SetSelection(long from, long to)
-Max
Hey Max,mc2r wrote:This might be what you are looking for,
The selection should be highlighted for you.http://www.wxwidgets.org/manuals/stable/wx_wxtextctrl.html#wxtextctrlsetselection wrote:wxTextCtrl::SetSelection
virtual void SetSelection(long from, long to)
-Max
I'm not at my code right now to take a blind stab, but in the wx manual I don't see a SetSelection() in wxTreeCtrl or any of it's parent classes. It does have a GetSelection(), so maybe it's just missing from the documentation?
http://www.wxwidgets.org/manuals/2.6/wx ... wxtreectrl
ToggleItemSelection() would work maybe but it's only for multi-select mode.
I'll try SetSelection tonight, but any other thought/ideas?
Thanks!
Jack
gurkesaft wrote:mc2r wrote:The selection should be highlighted for you.http://www.wxwidgets.org/manuals/stable/wx_wxtextctrl.html#wxtextctrlsetselection wrote:wxTextCtrl::SetSelection
virtual void SetSelection(long from, long to)
-Max
No, I'm just stupid/sloppy I didn't give you docs for wxTreeCtrl but wxTextCtrl.gurkesaft wrote:It does have a GetSelection(), so maybe it's just missing from the documentation?
Yeah, for wxTreeCtrl (not wxTextCtrl)gurkesaft wrote:I'll try SetSelection tonight, but any other thought/ideas?
This should work for single select or multi-selecthttp://www.wxwidgets.org/manuals/stable/wx_wxtreectrl.html#wxtreectrltoggleitemselection wrote:void wxTreeCtrl::SelectItem(const wxTreeItemId& item, bool select = true)
-Max
Hey Max,
Thanks for your prompt responses. SelectItem() is precisely the method I'm having trouble with. It selects it (and generates the selection event) but it doesn't appear in the tree control as highlighted.
I'm idly wondering if this has to do with the fact that I'm storing the TreeItemId of the next element and then removing an item from the list?
-Jack
Thanks for your prompt responses. SelectItem() is precisely the method I'm having trouble with. It selects it (and generates the selection event) but it doesn't appear in the tree control as highlighted.
I'm idly wondering if this has to do with the fact that I'm storing the TreeItemId of the next element and then removing an item from the list?
-Jack
I believe that is could be it. To delete selected items with multiple selection enabled you have to delete the selection closest to the end first and work your way back.gurkesaft wrote:I'm idly wondering if this has to do with the fact that I'm storing the TreeItemId of the next element and then removing an item from the list?
If you are deleting an item from before the selection, I'd delete first and then adjust the selection index by -1;
If you are deleting an item after the selection I'd delete first and the selection index should need no adjustment.
Hope that was clear and helps,
-Max
mc2r wrote:I believe that is could be it. To delete selected items with multiple selection enabled you have to delete the selection closest to the end first and work your way back.gurkesaft wrote:I'm idly wondering if this has to do with the fact that I'm storing the TreeItemId of the next element and then removing an item from the list?
If you are deleting an item from before the selection, I'd delete first and then adjust the selection index by -1;
If you are deleting an item after the selection I'd delete first and the selection index should need no adjustment.
Hope that was clear and helps,
-Max
Trees don't use indices for selection purposes, they use ID numbers, though. I don't think it's safe to increment them like that. Further, I do know that subsequent "GetSelection()" calls retrieve the right item. They just don't highlight for some reason.
-Jack
Okay, I whittled it down. Try this:
wxTreeItemId s = myTree->GetSelection();
myTree->SelectItem(s);
Pretty straightforward. As soon as you call SelectItem() the selection disappears. I've tried using Toggle() here once and twice just to see, and that doesn't do anything.
I can't see what I'm doing wrong here. I know I have access to the data associated with the tree item.
Crazy!
-Jack
wxTreeItemId s = myTree->GetSelection();
myTree->SelectItem(s);
Pretty straightforward. As soon as you call SelectItem() the selection disappears. I've tried using Toggle() here once and twice just to see, and that doesn't do anything.
I can't see what I'm doing wrong here. I know I have access to the data associated with the tree item.
Crazy!
-Jack