By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,050 Members | 1,564 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,050 IT Pros & Developers. It's quick & easy.

Possible bug in ToolStrip.Items.AddRange ?

P: n/a
I'm taking the items from a menustrip of a control and moving them to the
parent form's menustrip:

private void TakeMenus(AdminControl ac)
{
foreach (Control c in ac.Controls)
{
if (c is MenuStrip)
{
MenuStrip ms = (MenuStrip)c;
MainMenu.Items.AddRange(ms.Items);
ac.Controls.Remove(c);
}
}
}

Works perfectly. Then I have an almost identical routine to do the same for
ToolStrip:

private void TakeToolbars(AdminControl ac)
{
foreach (Control c in ac.Controls)
{
if (c is ToolStrip)
{
ToolStrip ts = (ToolStrip)c;
ac.Controls.Remove(c);
MainToolStrip.Items.AddRange(ts.Items);
}
}
}

This gives me an ArgumentOutOfRange exception!! I worked around it with the
following:

private void TakeToolbars(AdminControl ac)
{
foreach (Control c in ac.Controls)
{
if (c is ToolStrip)
{
ToolStrip ts = (ToolStrip)c;
for (int i = 0; i < ts.Items.Count; i++)
{
ToolStripItem tsi = ts.Items[i];
MainToolStrip.Items.Add(tsi);
i--;
}
ac.Controls.Remove(c);
}
}
}

That was weird....

Jon
Sep 25 '06 #1
Share this question for a faster answer!
Share on Google+

This discussion thread is closed

Replies have been disabled for this discussion.