Click here to Skip to main content
15,896,606 members
Home / Discussions / C#
   

C#

 
AnswerRe: Delete Data Pin
rohitsrivastava13-Sep-07 22:49
rohitsrivastava13-Sep-07 22:49 
GeneralRe: Delete Data Pin
Colin Angus Mackay13-Sep-07 23:24
Colin Angus Mackay13-Sep-07 23:24 
GeneralRe: Delete Data Pin
Dave Kreskowiak14-Sep-07 6:20
mveDave Kreskowiak14-Sep-07 6:20 
QuestionCombo Box Pin
sajid.salim.khan13-Sep-07 20:15
sajid.salim.khan13-Sep-07 20:15 
AnswerRe: Combo Box Pin
\laddie13-Sep-07 20:47
\laddie13-Sep-07 20:47 
AnswerRe: Combo Box Pin
rohitsrivastava13-Sep-07 22:08
rohitsrivastava13-Sep-07 22:08 
QuestionIterarting menu item Pin
Amar Chaudhary13-Sep-07 19:54
Amar Chaudhary13-Sep-07 19:54 
AnswerRe: Iterarting menu item Pin
ElSpinos13-Sep-07 22:42
ElSpinos13-Sep-07 22:42 
Greetings Amar,

If you look at how the MenuStrip control works you will notice that it houses a different type of collection, the ToolStripItemCollection in its MenuStrip.Items property. You need to iterate each ToolStripMenuItem in that collection to get its children.

After that, the ToolStripMenuItem has another ToolStripItemCollection in it's DropDownItems property, you now need to iterate through this collection to get it's children and so forth... consider the following example:

<br />
void ListControls(Control parentControl)<br />
{<br />
	foreach (Control control in parentControl.Controls)<br />
	{<br />
		MessageBox.Show("Control Type   : " + control.GetType().ToString() + "\n" +<br />
		                "Has Children   : " + (control.Controls.Count > 0 ? "Yes" : "No") + "\n");<br />
		<br />
		// Perform the child-find functionality on the ControlCollection here.<br />
		if (control.Controls.Count > 0)<br />
		{<br />
		// Call ourselves to discover additional children...<br />
		 this.ListControls(control);<br />
		}<br />
		<br />
		// Get the sub menus of a MenuStrip.<br />
		// * Test for the type of control, we're looking for the MenuStrip here...<br />
		// TODO: Add this to a different function to nest-find child tool strips.<br />
		if (control.GetType() == typeof(MenuStrip))<br />
		{<br />
		 // As you can see, the menu houses a collection of items not controls, notice this is now a ToolStripItemcollection not ControlCollection.<br />
		 foreach (ToolStripMenuItem toolStripMenuItem in ((MenuStrip)control).Items)<br />
		 {<br />
		  MessageBox.Show("---> Menu Strip '" + ((MenuStrip)control).Text + "' has '" + toolStripMenuItem.Text + "' as a child item.");<br />
		  // Test if tool strip has child items, notice this is a ToolStripItemcollection too.<br />
		  if (toolStripMenuItem.DropDownItems.Count > 0)<br />
		  {<br />
		   // Call your nested-find function...<br />
		  }<br />
		 }<br />
		}<br />
	}<br />
}<br />


Basically, the MenuStrip needs to be treated like a TreeView as it can contain a complex hierarchy. I hope this helps... Have a great weekend!



Fernando Mendes
Senior .NET Developer, Architect

GeneralRe: Iterarting menu item Pin
Amar Chaudhary14-Sep-07 3:12
Amar Chaudhary14-Sep-07 3:12 
QuestionRegarding Telnet Pin
pashitech13-Sep-07 19:31
pashitech13-Sep-07 19:31 
AnswerRe: Regarding Telnet Pin
\laddie13-Sep-07 19:39
\laddie13-Sep-07 19:39 
GeneralRe: Regarding Telnet Pin
\laddie13-Sep-07 19:40
\laddie13-Sep-07 19:40 
AnswerRe: Regarding Telnet Pin
PIEBALDconsult14-Sep-07 4:44
mvePIEBALDconsult14-Sep-07 4:44 
QuestionUrgent button disabling problem Pin
Sunshine Always13-Sep-07 19:29
Sunshine Always13-Sep-07 19:29 
AnswerRe: Urgent button disabling problem Pin
\laddie13-Sep-07 19:38
\laddie13-Sep-07 19:38 
GeneralRe: Urgent button disabling problem Pin
Sunshine Always13-Sep-07 20:11
Sunshine Always13-Sep-07 20:11 
GeneralRe: Urgent button disabling problem Pin
vikas maan13-Sep-07 20:58
vikas maan13-Sep-07 20:58 
Questionnot inheriting control from base class Pin
falles0113-Sep-07 17:40
falles0113-Sep-07 17:40 
AnswerRe: not inheriting control from base class Pin
vikas maan13-Sep-07 21:00
vikas maan13-Sep-07 21:00 
AnswerRe: not inheriting control from base class Pin
rohitsrivastava13-Sep-07 21:15
rohitsrivastava13-Sep-07 21:15 
GeneralRe: not inheriting control from base class Pin
Pete O'Hanlon13-Sep-07 22:16
mvePete O'Hanlon13-Sep-07 22:16 
QuestionTo copy a file Pin
P_Elza13-Sep-07 17:10
P_Elza13-Sep-07 17:10 
AnswerRe: To copy a file Pin
Scott Dorman13-Sep-07 17:23
professionalScott Dorman13-Sep-07 17:23 
Questionproblem about c# Pin
cam chuong13-Sep-07 15:52
cam chuong13-Sep-07 15:52 
AnswerRe: problem about c# Pin
Dave Kreskowiak13-Sep-07 17:23
mveDave Kreskowiak13-Sep-07 17:23 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.