For 3 days now I've been searching the answer to this seemingly easy question.
I've created a class like so:
public class SourceMenuItem : ToolStripMenuItem
{
private string connection;
public string Conn
{
get
{
return connection;
}
set
{
connection = value;
}
}
}
My ToolStripMenuItem control is called SourceLeft System.Windows.Forms.ToolStripMenuItem
Here's how I dynamically add items
SourceMenuItem item = new SourceMenuItem();
item.Text = "drive c:";
item.Tag = "drive";
item.Conn = "my string to retrieve";
// (other stuff like ToolTipText, etc...)
SourceLeft.DropDownItems.Add(item);
And here's how I retrieve the values
string text = "";
string tag = "";
string conn = "";
int max = SourceLeft.DropDownItems.Count;
for (i = 0; i < max; ++i)
{
text = SourceLeft.DropDownItems[i].Text;
tag = SourceLeft.DropDownItems[i].Tag.ToString(); // I have no problem retrieving those stored values.
// Here's where the problem starts conn = SourceLeft.DropDownItems[i].Conn;
}
The error message for .Conn is to be expected:
ToolStripItem does not contain a definition for 'Conn' and no accessible extension method 'Conn' accepting a first argument of type 'ToolStripItem' could be found.
I'm new to C# and couldn't find the answer about the code I'm missing to make this work:
I wish to address the .Conn property the same way I do with .Text & .Tag
Thank you for all your help
Have a nice day.