Windows Develop Bookmark and Share   
 index > Windows Forms General > same context menu strip on multiple controls???Possible????
 

same context menu strip on multiple controls???Possible????

Hi All

i have 4 combo boxes and one context menu strip.this context menu strip is attached with all the 4 combo boxes.
this menu has only one button "clear" which will clear the combo box value and set the selected index to -1.The purpose of the context menu is to set the combo box selected index to -1.
Is it possible to get the control to which the context menu strip is activited.

my probelm is i cant get the combo box on which the menu strip was activited or called or displayed what what you call it

plzzz help

thanks




C# lover
sohail Khaliq  Thursday, May 07, 2009 7:44 AM
Yes its possible, use the SourceControl property of the ContextMenuStrip. The following code snippet shows how to get the ContextMenuStrip when handling a ToolStripMenuItem Click event (and set the combo box selected index to -1):

		private void someToolStripMenuItem_Click(object sender, EventArgs e)
		{
			ToolStripMenuItem item = (ToolStripMenuItem)sender;
			ContextMenuStrip strip = (ContextMenuStrip)item.Owner;
			((ComboBox)strip.SourceControl).SelectedIndex = -1;
		}

/Calle
- Still confused, but on a higher level -
  • Proposed As Answer byMIkeTims Thursday, May 07, 2009 11:34 AM
  • Marked As Answer bysohail Khaliq Thursday, May 07, 2009 2:25 PM
  •  
Calle Mellergardh  Thursday, May 07, 2009 11:33 AM
Yes its possible, use the SourceControl property of the ContextMenuStrip. The following code snippet shows how to get the ContextMenuStrip when handling a ToolStripMenuItem Click event (and set the combo box selected index to -1):

		private void someToolStripMenuItem_Click(object sender, EventArgs e)
		{
			ToolStripMenuItem item = (ToolStripMenuItem)sender;
			ContextMenuStrip strip = (ContextMenuStrip)item.Owner;
			((ComboBox)strip.SourceControl).SelectedIndex = -1;
		}

/Calle
- Still confused, but on a higher level -
  • Proposed As Answer byMIkeTims Thursday, May 07, 2009 11:34 AM
  • Marked As Answer bysohail Khaliq Thursday, May 07, 2009 2:25 PM
  •  
Calle Mellergardh  Thursday, May 07, 2009 11:33 AM
look at the contextmenustrips SourceControl property.
Mick Doherty
http://dotnetrix.co.uk
Mick Doherty  Thursday, May 07, 2009 11:36 AM

You can use google to search for other answers

Custom Search

More Threads

• How an application will be launched after setup is completed and user click close button?
• How to add this missing reference <<basic>>
• Performing mouse click in C#
• Dropdown of classes
• Creating A Form From a Class
• non rectengular form flickers at moving
• ListBox and Mysql
• problem Loading AutoSuggest in TeXtBox
• Main Form not showing up in taskbar
• Mouse Scroll Wheel Input