Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Here's one slightly ugly way to do it, by using the Tag property of the DropDownItem.</p> <p>Using your code:</p> <pre><code>var item = new ToolStripMenuItem(string name, image, eventargs onClick); item.Tag = "your.ip.address"; ToolStripMenuItem.DropDownItems.Add(item) </code></pre> <p>Then,</p> <pre><code>private void addToolStripMenuItem_Click(object sender, EventArgs e) { var item = sender as ToolStripMenuItem; Room r = new Room(); r.Name ="Name"; r.IP = item.Tag.ToString(); r.passwrd="Password"; presetsToolStripMenuItem.DropDownItems.Add(r.Name, null, disp); } </code></pre> <p><strong>A different possible solution:</strong></p> <p>I'm not sure how your classes are laid out, but you might want to have a separate lookup class that stores a mapping of Name->IP. Then do something like this,</p> <pre><code>var item = sender as ToolStripMenuItem; IPLookuper.GetIP(item.Text);//.Text corresponds to name in "ToolStripMenuItem(string name,..." </code></pre> <p>A lookup is easy enough, just throw the items in a Dictionary.</p> <p><strong>3rd edit</strong></p> <p>Because you know the type that calls the disp method, you could think of it like this,</p> <pre><code> void disp(ToolStripMenuItem sender, EventArgs e) { var ip = sender.Tag.ToString(); //Lookup the name/password/whatever based on the IP. MessageBox.Show(r.Name's IP address); MessageBox.Show(r.Name's password); } </code></pre> <p>the sender object is just whatever class fired off the event, so you can cast it if you know what type it is.</p> <p>Since your actual code uses 'object sender', you'll just have to cast it yourself.</p> <pre><code> void disp(object sender, EventArgs e) { var item = sender as ToolStripMenuItem; var ip = item.Tag.ToString(); //Lookup the name/password/whatever based on the IP. MessageBox.Show(r.Name's IP address); MessageBox.Show(r.Name's password); } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload