M
MWS
Hello,
I'm trying to loop through the app.Config file and add the keys from
the app.Config as MenuItems on a MenuStrip. The following line blows
up...
transToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] {
TransMenuItem[TransCount]});
The error that I'm getting is "ArgumentNullExceiption was unhandled"
because TransMenuItem[TransCount] is null. Could someone please post a
code snippet out there with an example of how to dynamically add
menuItems to a menustrip? I've seen examples, but all of them have
hard coded declairations of the ToolStripMenuItems. I need to loop
though the app.config and declare the ToolStripMenuItems.
//TransCount is an integer that equals 5 at this point
ToolStripMenuItem[] TransMenuItems = new
ToolStripMenuItem[TransCount];
TransCount = 0;
foreach (string keyname in settings.Allkeys){
transToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] {
TransMenuItem[TransCount]});
TransMenuItems[TransCount].Name = "XXX";
TransMenuItems[TransCount].Text = "XXX";
TransCount++;
}
I'm trying to loop through the app.Config file and add the keys from
the app.Config as MenuItems on a MenuStrip. The following line blows
up...
transToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] {
TransMenuItem[TransCount]});
The error that I'm getting is "ArgumentNullExceiption was unhandled"
because TransMenuItem[TransCount] is null. Could someone please post a
code snippet out there with an example of how to dynamically add
menuItems to a menustrip? I've seen examples, but all of them have
hard coded declairations of the ToolStripMenuItems. I need to loop
though the app.config and declare the ToolStripMenuItems.
//TransCount is an integer that equals 5 at this point
ToolStripMenuItem[] TransMenuItems = new
ToolStripMenuItem[TransCount];
TransCount = 0;
foreach (string keyname in settings.Allkeys){
transToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] {
TransMenuItem[TransCount]});
TransMenuItems[TransCount].Name = "XXX";
TransMenuItems[TransCount].Text = "XXX";
TransCount++;
}