Guidance
指路人
g.yi.org
Guidance Forums / wxWidgets (wxWindows) in C++ / How can I swap items in wxList and wxTreeCtrl ?

Register 
注册
Search 搜索
首页 
Home Home
Software
Upload

  
Forum List • Thread List • Reply • Refresh • New Topic • Search • Previous • Next First 1 Last
Message1. How can I swap items in wxList and wxTreeCtrl ?
#3014
Posted by: 2003-11-28 15:13:23
I really cant find any decent way how to do this.
Thx for your patience with me :o|.
Message2. Re: How can I swap items in wxList and wxTreeCtrl ?
#3015
Posted by: 2003-11-28 17:47:13
I guess you want to actually swich the pointers that link the nodes?

Probably possible some way, but i would just use insert and delete the items i guess.

for swap A and B:      (Index A < Index B)
Insert Item A at position B+1
Insert Item B at position A+1
Delete Item At position A
Delete Item At Position B

(If this is really stupid or anything, thats because i'm just a newbie programmer)
Message3. Re: How can I swap items in wxList and wxTreeCtrl ?
#3017
Posted by: 2003-11-28 22:48:22
U cant create item and then insert it coz there is no function to insert or add item by ptr ( AppendItem(itemPtr) or InsertItem(itemPtr) ).And it looks there is no way to create standalone item.
I found only function to add or insert new item:

  AppendItem(const wxTreeItemId& parent, const wxString& text, int image = -1, int selImage = -1, wxTreeItemData* data = NULL)

  InsertItem(const wxTreeItemId& parent, size_t before, const wxString& text, int image = -1, int selImage = -1, wxTreeItemData* data = NULL)

Most of wxTreeCtrl functions returns wxTreeItemId - this should be some sort of handle but I dont know how to swap item using this handle. I am new in wxWindows and if I am wrong pls help.Thx a lot.
Message4. Re: How can I swap items in wxList and wxTreeCtrl ?
#3043
Posted by: 2003-12-02 21:38:08
I'm new to it as well, but trying to help anyway (people help me, so i think i should try to help back)

maybe use this function to get itemdata from ID so you can use the insert function:

wxTreeItemData* GetItemData(const wxTreeItemId& item) const

Since i am also new, if i am wrong, anyone else, dont hessitate to tell me and help the original poster with better advise.
Message5. Re: How can I swap items in wxList and wxTreeCtrl ?
#3047
Posted by: upCASE 2003-12-03 16:54:03
Hi!
The problem really is what you want to swap.
If it's only single items it shouldn't that hard to implement, but to swap whole nodes, meaning item that have child items and you need the whole branch at a new position, could be harder to implement.
So far I didn't have the time to investigate how wxTreeCtrl is implemented. wxTreeItemId is a wrapper around some arbitrary handle but the interesting part is, if wxTreeCtrl or wxTreeItemId (or maybe even wxTreeItemData) stores the references to the next node and child. I guess that if you're lucky you could go with getting the wxTreeItemId and wxTreeItemData and using wxTreeItemData::SetId(), but if wxTreeCtrl holds control about the list in generl this is likely to segfault.

Being at work I don't have the time and chance to verify this. When I find the time tomorrow I'll check.

BTW: Have you tried contacting the mailing list or searched the archives? This doesn't seem to me like a thing nobody ever wants to do, so maybe there was a posting about this topic.

upcase
upCASE
-----------------------------------
If it was hard to write, it should be hard to read!- Do. Or do not. There is no try!
Message6. Re: How can I swap items in wxList and wxTreeCtrl ?
#3054
Posted by: 2003-12-09 17:20:49
I am swapping whole nodes.
I checked mailing list - noone know how to do it by pointers so I did it manually - I wrote copyTreeItems() function.

I still think that functions like MoveTo() or Exchange() should be implemented in classes like wxTreeCtrl or wxList :o).
Forum List • Thread List • Reply • Refresh • New Topic • Search • Previous • Next First 1 Last
掌柜推荐
 
 
 
 
 
 
 
 
 
 
 
 
© Tue 2024-12-10  Guidance Laboratory Inc.
Email:webmaster1g.yi.org Hits:0