I have a ContextMenuStrip inside a form.
For some reason, I want to change all items of the context menu simultaneously. So I wrote this peace of code:
int a = 0;
foreach (ToolStripItem co in contextMenuStrip1.Items)
{
co.Text = "Menu" + a.ToString();
a++;
}
But although the main items change succesfully, the subitems doesn't change
So how can I have access to those subitems too?
PS: I cannot add an image because I am new to this forum to see what I mean, I hope you get the idea.
Thanks!
Best Answer
You need to cast to
ToolStripDropDownItem
and check theDropDownItems
property. And, of cource, update it recursively.here is the sample:
How to use: