473,379 Members | 1,191 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,379 software developers and data experts.

Show Control in DropDown of ToolStripMenuItem

I need to show a custom control in the DropDown of a
Windows.Forms.ToolStripMenuItem (e.g., similar to the Font Color menu item in
Word except that the control is specific to my application). I tried adding
the control to Windows.Forms.ToolStripMenuItem.DropDown.Controls but doing so
raises a NotSupported exception. Are there any standard ToolStripItems
and/or techniques for implementing this type of functionality?

Thanks for any help!
Lance

May 16 '07 #1
3 8555
Hi Lance,

Based on my understand, you want to showing a customized control in the
ToolStripMenuItem DropDown property.

To get this done, you should not use ToolStripMenuItem.DropDown.Controls
property. The correct solution is using ToolStripControlHost to host your
customize control and add ToolStripControlHost to ToolStripDropDown.Items
collection. I created a little sample application demonstrating the usage:

private void Form1_Load(object sender, EventArgs e)
{
TreeView treeview = new TreeView();
TreeNode treeNode1=new TreeNode();
treeview.Name = "treeview";
treeNode1.Name = "Node1";
treeNode1.Text = "Node1";
treeview.Nodes.AddRange(new System.Windows.Forms.TreeNode[] {treeNode1
});

treeview.BorderStyle = BorderStyle.None;
ToolStripControlHost treeViewHost = new ToolStripControlHost(treeview);
ToolStripDropDown dropDown = new ToolStripDropDown();
dropDown.Items.Add(treeViewHost);

this.toolStripMenuItem1.DropDown = dropDown;
}
Note: I created a TreeView control and hosted it in ToolStripControlHost,
finally, I added it into ToolStripDropDown.Items collection.

The articles below contains more information:
"Writing custom popup controls"
http://blogs.msdn.com/jfoscoding/arc...18/471048.aspx
"Adding a custom control to a ToolStripDropDownButton"
http://www.codeproject.com/cs/menu/T...ipDropDown.asp

Hope this helps.

Best regards,
Jeffrey Tan
Microsoft Online Community Support
==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscripti...ult.aspx#notif
ications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscripti...t/default.aspx.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.

May 17 '07 #2
Hi Lance,

Oh, sorry, it seems that I pasted the C# code by mistake. Below is the
VB.net version:

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
Dim treeview As New TreeView()
Dim treeNode1 As New TreeNode()
treeview.Name = "treeview"
treeNode1.Name = "Node1"
treeNode1.Text = "Node1"
treeview.Nodes.AddRange(New System.Windows.Forms.TreeNode()
{treeNode1})

treeview.BorderStyle = BorderStyle.None
Dim treeViewHost As New ToolStripControlHost(treeview)
Dim dropDown As New ToolStripDropDown()
dropDown.Items.Add(treeViewHost)

Me.ToolStripMenuItem1.DropDown = dropDown
End Sub

Thanks.

Best regards,
Jeffrey Tan
Microsoft Online Community Support
==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscripti...ult.aspx#notif
ications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscripti...t/default.aspx.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.

May 17 '07 #3
Hi Jeffrey,

That's great. Thanks a lot! I misunderstood the purpose of the
ToolStripControlHost so your sample was very helpful.

Thanks again,
Lance

May 17 '07 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: tom | last post by:
Hi, I want a listbox below a hidden calendar control. The problem is that the listbox will shadow the calendar when the calendar is visible. How can I bring the calendar from back to front? ...
3
by: RJN | last post by:
Hi The texts in the dropdown are too long and the width is not sufficient to show the entire text. Increasing the width is not an option. Is there a way to show the selected item text as a...
2
by: Sakharam Phapale | last post by:
Hi All, How to show dropdown list of menu items just like click on Parent menu. For example, Edit (Parent menu) Cut (child menu) Copy (child menu) Paste (child menu)
5
by: Marc | last post by:
Hello, I have a vb.net form that I've added a StatusStrip at the bottom. On that StatusStrip I've added a DropDownButton on which I've added a Menu containing 4 sub Items
2
by: Manekurt | last post by:
Hello to everyone, I have this code, that gives me an error on the marked line. It is to make a reference to a submenuitem, to enable it thorgh it name. Error line: For Each oSubitem As...
15
by: cj | last post by:
I would like to have menu items a main menu bar that represent the days of the week. When you click on them they alternate from checked to unchecked. Right now I have 7 subs that look like this...
0
by: Dean Slindee | last post by:
I need to be able to separate toolstripmenuitems from toolstripseparators, both of which are children of a toolstripdropdropbutton. The last statement does not pass validation. Is there any way...
3
by: Martijn Mulder | last post by:
My application has a standard MenuStrip on top of the window and a ContextMenuStrip that pops up when the user clicks the right mouse button. I have defined a ToolStripMenuItem that I want to...
8
by: =?Utf-8?B?bWljaGFlbCBzb3JlbnM=?= | last post by:
I created a user control that handles certain keystrokes, e.g. Ctrl-C for cut, Ctrl-V for paste, plus other more specialized keystrokes. I want to list these in the menubar like any other menu...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.