wxTreeCtrl SelectItem selects but doesn't highlight the item

If you are using the main C++ distribution of wxWidgets, Feel free to ask any question related to wxWidgets development here. This means questions regarding to C++ and wxWidgets, not compile problems.
Post Reply
gurkesaft
Experienced Solver
Experienced Solver
Posts: 54
Joined: Mon Jul 17, 2006 1:48 pm

wxTreeCtrl SelectItem selects but doesn't highlight the item

Post by gurkesaft »

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
mc2r
wxWorld Domination!
wxWorld Domination!
Posts: 1195
Joined: Thu Feb 22, 2007 4:47 pm
Location: Denver, Co
Contact:

Post by mc2r »

This might be what you are looking for,
http://www.wxwidgets.org/manuals/stable/wx_wxtextctrl.html#wxtextctrlsetselection wrote:wxTextCtrl::SetSelection

virtual void SetSelection(long from, long to)
The selection should be highlighted for you.

-Max
gurkesaft
Experienced Solver
Experienced Solver
Posts: 54
Joined: Mon Jul 17, 2006 1:48 pm

Post by gurkesaft »

mc2r wrote:This might be what you are looking for,
http://www.wxwidgets.org/manuals/stable/wx_wxtextctrl.html#wxtextctrlsetselection wrote:wxTextCtrl::SetSelection

virtual void SetSelection(long from, long to)
The selection should be highlighted for you.

-Max
Hey 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
mc2r
wxWorld Domination!
wxWorld Domination!
Posts: 1195
Joined: Thu Feb 22, 2007 4:47 pm
Location: Denver, Co
Contact:

Post by mc2r »

gurkesaft wrote:
mc2r wrote:
http://www.wxwidgets.org/manuals/stable/wx_wxtextctrl.html#wxtextctrlsetselection wrote:wxTextCtrl::SetSelection

virtual void SetSelection(long from, long to)
The selection should be highlighted for you.

-Max
gurkesaft wrote:It does have a GetSelection(), so maybe it's just missing from the documentation?
No, I'm just stupid/sloppy ;) I didn't give you docs for wxTreeCtrl but wxTextCtrl.
gurkesaft wrote:I'll try SetSelection tonight, but any other thought/ideas?
Yeah, for wxTreeCtrl (not wxTextCtrl)
http://www.wxwidgets.org/manuals/stable/wx_wxtreectrl.html#wxtreectrltoggleitemselection wrote:void wxTreeCtrl::SelectItem(const wxTreeItemId& item, bool select = true)
This should work for single select or multi-select

-Max
gurkesaft
Experienced Solver
Experienced Solver
Posts: 54
Joined: Mon Jul 17, 2006 1:48 pm

Post by gurkesaft »

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
mc2r
wxWorld Domination!
wxWorld Domination!
Posts: 1195
Joined: Thu Feb 22, 2007 4:47 pm
Location: Denver, Co
Contact:

Post by mc2r »

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?
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.

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
gurkesaft
Experienced Solver
Experienced Solver
Posts: 54
Joined: Mon Jul 17, 2006 1:48 pm

Post by gurkesaft »

mc2r wrote:
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?
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.

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
gurkesaft
Experienced Solver
Experienced Solver
Posts: 54
Joined: Mon Jul 17, 2006 1:48 pm

Post by gurkesaft »

are we tapped? :)

Thanks for your efforts!

-Jack
mc2r
wxWorld Domination!
wxWorld Domination!
Posts: 1195
Joined: Thu Feb 22, 2007 4:47 pm
Location: Denver, Co
Contact:

Post by mc2r »

gurkesaft wrote:are we tapped? :)

Thanks for your efforts!

-Jack
Not sure about we, but I'm. For now at least. In the middle of a grueling bug hunt and don't have many spare cycles.

-Max
gurkesaft
Experienced Solver
Experienced Solver
Posts: 54
Joined: Mon Jul 17, 2006 1:48 pm

Post by gurkesaft »

Okay, thanks for your help and good luck with the bug!

Update: I tried selecting the next item *before* moving the initial item, but it still doesn't highlight. I think next I'll try just not moving the item at all. I wish I was at my proggy now, but alas. Must earn munnies.

-Jack
gurkesaft
Experienced Solver
Experienced Solver
Posts: 54
Joined: Mon Jul 17, 2006 1:48 pm

Post by gurkesaft »

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
Post Reply