Grasshopper

algorithmic modeling for Rhino

Change name of another component when name of component is changed

Hi Everyone,

I want to have a situation where component 1 is linked to component 2 so that when the name of the component 1 is changed, the name of component 2 will update.

However, unfortunately I can't find a clean hook to do this, I tried overriding the default textbox on each GH component where the name can be set, with the code below which will call my own event for the name change.

However unforunately I can't add my custom ToolStripTextBox to the AppendMenuItems.

Any ideas? Thanks!

public override bool AppendMenuItems(System.Windows.Forms.ToolStripDropDown menu)
{


ToolStripTextBox toolStripTextBox = new ToolStripTextBox(this.NickName);

toolStripTextBox.TextChanged += new EventHandler(NameChanged);

ToolStripMenuItem toolStripMenuItemName = GH_DocumentObject.Menu_AppendItem()

// Custom event which is called when the name is changed and the other component's name will be updated:


private void NameChanged(object sender, EventArgs e)
{
ToolStripTextBox textBox = (ToolStripTextBox)sender;

this.NickName = textBox.Text;

this.linkedCheckList.NickName = textBox.Text;

}

Views: 562

Replies to This Discussion

You can do like this.

public override bool AppendMenuItems(System.Windows.Forms.ToolStripDropDown menu)

{

GH_DocumenObject.Menu_AppendTextItem(menu, this.NickName,new GH_MenuTextBox.KeyDownEventHandler(NameChanged), null, true);

}

private void NameChanged(GH_MenuTextBox sender, KeyEventArgs e)
{
    Keys keyCode = e.KeyCode;
    if (keyCode == System.Windows.Forms.Keys.Return)
    {
         ToolStripTextBox textBox = (ToolStripTextBox)sender;

         this.NickName = textBox.Text;

         this.linkedCheckList.NickName = textBox.Text;
    }
    else if (keyCode == Keys.Escape || keyCode == Keys.Cancel)
    {
    }
}

Panda,

As always many thanks! Unfortunately at the line:

ToolStripTextBox textBox = (ToolStripTextBox)sender;

It is telling me that GH_MenuTextBox cannot be converted to toolStripTextbox, did you build a cast for GH_MenuTextBox? I am going to try doing this

    Sorry,it my fault!Just like this,

    if (keyCode == System.Windows.Forms.Keys.Return)
    {

         this.NickName = sender.Text;

         this.linkedCheckList.NickName = sender.Text;
    }

Thanks Panda,

Do you have some code that, can use the commit and cancel changes tabs as well? I'm not sure exactly how to access them?

Attachments:

The commit and cancel changes tabs are parts of  GH_MenuTextBox.

RSS

About

Translate

Search

Photos

  • Add Photos
  • View All

Videos

  • Add Videos
  • View All

© 2024   Created by Scott Davidson.   Powered by

Badges  |  Report an Issue  |  Terms of Service