It seems that you're using an outdated browser. Some things may not work as they should (or don't work at all).
We suggest you upgrade newer and better browser like: Chrome, Firefox, Internet Explorer or Opera

×
I'm trying to do a couple of things with a tree control in wxWidgets:

- Allow label editing

- Allow drag and drop to move things around within the tree hierarchy

And when I do both of these things, I need to get the data of which items are being changed and in which way (what the label is being changed to, or where the item is being moved to, depending on which of the two actions it is).

Also, the names must be unique, so I need to be able to prevent a label from being changed if it becomes identical to a different one, or if it's an invalid format (however I arbitrarily define that), and I must prevent them from being moved if they get moved to somewhere I consider invalid (also however I define it).

So at the moment, it's letting me change the labels, and I can capture the events when I begin and end the editing. However, I have to figure out which one is being edited and get the data from it, before and after editing, so that I can revert it if necessary and possibly display an error message. I also need to prevent some of them from being edited, because some aren't allowed to be.

I can't seem to prevent the editing though. I don't know if there's a way to signal the event to just cancel it, but that's what I'll need to do. As for figuring out which item was clicked (assuming that the label editing begins by clicking it, otherwise I have NO idea how to determine which one is being edited!), I already had some code for checking when I right-click on one and figuring out which one it is, and that was working fine, but when I try to implement the same code into the label editing event, it doesn't work right:

wxPoint mousePosition = tree->ScreenToClient(wxGetMousePosition());
currentItem = tree->HitTest(mousePosition);
TreeItemData* itemData = (TreeItemData*)(tree->GetItemData(currentItem));

For some reason, the mouse position that it gives me is wildly different depending on whether I do this stuff within the right-click event or the label edit begin event, but it should be exactly the same! So in the label edit event it often gives me a position which is either the wrong item, or not even on the tree, and it can't get the item, so it crashes!

As for the drag and drop, I can get it to notice when I try to begin a drag, but it doesn't seem to call the event for ending the drag, which I'll need to also do. In any case, it will also need to know which item is being dragged and onto which other item. And like with the label editing, it will need to be able to limit which ones can be dragged, and which ones can have things dragged onto them.

Does anyone know how to do any of this? Help with any part of it would be appreciated, thanks!
Post edited May 14, 2023 by HeresMyAccount
No posts in this topic were marked as the solution yet. If you can help, add your reply