Overview
Examples
Screenshots
Comparisons
Applications
Download
Documentation
Tutorials
Bazaar
Status & Roadmap
FAQ
Authors & License
Forums
Funding Ultimate++
Search on this site
Search in forums












SourceForge.net Logo
Home » U++ Library support » TreeCtrl » Editing TreeCtrl Node Value
Editing TreeCtrl Node Value [message #34446] Tue, 22 November 2011 19:24 Go to next message
bushman is currently offline  bushman
Messages: 134
Registered: February 2009
Experienced Member
Is there a way of changing a TreeCtrl Node Value, say, the same way as you do in an ArrayCtrl Column, when you click a second time on a column previously assigned for editing through ArrayCtrl::Edit(Ctrl& ctrl)?

I couldn't find a corresponding method for TreeCtrl, such as TreeCtrl::Node::Edit(Ctrl& ctrl).

Any suggestions on how I should go about it, like a code sample ?


Thanks!

Re: Editing TreeCtrl Node Value [message #34476 is a reply to message #34446] Fri, 25 November 2011 01:50 Go to previous messageGo to next message
bushman is currently offline  bushman
Messages: 134
Registered: February 2009
Experienced Member
I improvised with the following code:

.h:
class App : public TopWindow {	
  public:
    typedef App CLASSNAME;
    App();

  private:
    struct TreeEdit : public EditString {
      Callback WhenLostFocus;
      TreeEdit() {}
      virtual void LostFocus() { WhenLostFocus(); }
    };
		
    bool                isedit;
    int                 nodeid;
    TreeCtrl::Node	editnode, node;
    TreeEdit		edit;
    TreeCtrl            tree;
		
    void EditBranch();
    void CloseEdit();
};


.cpp:
App::App() : isedit(false), nodeid(-1) {
   Add(tree.SizePos());
  /*
   ...
   Populate TreeCtrl here
   ...
  */
   tree.WhenLeftClick = THISBACK(EditBranch);
   editnode.SetCtrl(edit);
   edit.WhenEnter = THISBACK(CloseEdit);
   edit.WhenLostFocus = THISBACK(CloseEdit);
}

void App::EditBranch()
{
  if(isedit) {
    CloseEdit();
    return;
  }
  if(nodeid != tree.GetCursor()) {
    nodeid = tree.GetCursor();
    return;
  }
  isedit = true;
  node = tree.GetNode(nodeid);
  editnode.ctrl->SetData(node.value);
  editnode.image = node.image;
  groups.SetNode(nodeid, editnode);
  editnode.ctrl->Show();
}

void App::CloseEdit()
{
  node.value = editnode.ctrl->GetData();
  tree.SetNode(nodeid, node);
  tree.SelectOne(nodeid);
  editnode.ctrl->Hide();
  isedit = false;
}



It works in a way, but I guess there must be an easier way of acomplishing this.

thanks for any help.
Re: Editing TreeCtrl Node Value [message #34488 is a reply to message #34476] Fri, 25 November 2011 13:49 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 13975
Registered: November 2005
Ultimate Member
kropniczki wrote on Thu, 24 November 2011 19:50

I improvised with the following code:

.h:
class App : public TopWindow {	
  public:
    typedef App CLASSNAME;
    App();

  private:
    struct TreeEdit : public EditString {
      Callback WhenLostFocus;
      TreeEdit() {}
      virtual void LostFocus() { WhenLostFocus(); }
    };
		
    bool                isedit;
    int                 nodeid;
    TreeCtrl::Node	editnode, node;
    TreeEdit		edit;
    TreeCtrl            tree;
		
    void EditBranch();
    void CloseEdit();
};


.cpp:
App::App() : isedit(false), nodeid(-1) {
   Add(tree.SizePos());
  /*
   ...
   Populate TreeCtrl here
   ...
  */
   tree.WhenLeftClick = THISBACK(EditBranch);
   editnode.SetCtrl(edit);
   edit.WhenEnter = THISBACK(CloseEdit);
   edit.WhenLostFocus = THISBACK(CloseEdit);
}

void App::EditBranch()
{
  if(isedit) {
    CloseEdit();
    return;
  }
  if(nodeid != tree.GetCursor()) {
    nodeid = tree.GetCursor();
    return;
  }
  isedit = true;
  node = tree.GetNode(nodeid);
  editnode.ctrl->SetData(node.value);
  editnode.image = node.image;
  groups.SetNode(nodeid, editnode);
  editnode.ctrl->Show();
}

void App::CloseEdit()
{
  node.value = editnode.ctrl->GetData();
  tree.SetNode(nodeid, node);
  tree.SelectOne(nodeid);
  editnode.ctrl->Hide();
  isedit = false;
}



It works in a way, but I guess there must be an easier way of acomplishing this.

thanks for any help.


Unfortunately, this mode of edit is not directly supported (yet?).
Re: Editing TreeCtrl Node Value [message #34490 is a reply to message #34488] Fri, 25 November 2011 15:31 Go to previous message
bushman is currently offline  bushman
Messages: 134
Registered: February 2009
Experienced Member
Quote:

Unfortunately, this mode of edit is not directly supported (yet?).

All right, thank you, now I know officially it is not supported (yet), so I'll try to cope with what we got for now at least, for I read in your question mark maybe it might be included in a future version of TreeCtrl, right?

Thanks.
Previous Topic: PROPOSAL : allow inserting and retrieving of classes DERIVED from TreeCtrl::Node
Next Topic: PROPOSAL: seperate backend from frontend
Goto Forum:
  


Current Time: Fri Apr 19 10:52:25 CEST 2024

Total time taken to generate the page: 0.02610 seconds