Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Populate a Button in a ToolStrip 1

Status
Not open for further replies.

plopez

Technical User
Apr 2, 2002
66
CL
Hi,
I need to populate in run-time a button with several items in a ToolStrip Control in VB2005.

If someone can help me I thank so much.
 
Dim button2 As New ToolStripButton
button2.Text = "Test"
Me.ToolStrip1.Items.AddRange(New System.Windows.Forms.ToolStripItem() {button2})
 
Hi Macleod1021

My problem are the "Items" of a Button...something like this:

Button1 Button2 Button3
Item1
Item2
Item3

I need to create in run-time Item1,Item2,Item3.

Is that possible?
Thank you for your help.
 
Anything that you can create in the design time can be created in the run time. What I would recommend you do is create a "Test Project" with just the default settings. Then under "Project" choose "Show All Files". This will add additional files in your Solution Explorer. By drilling into Form 1, you'll see a file named "Form1.designer.vb". Open that and you'll see all of the Automatically created code. Once you know where that is, the fun can begin :)

Go back to your form designer and create your tool strip buttons the way you want it during Run-Time. Then, go to your designer.vb file and find the new entries. It will have the code exactly as you need it. Copy and paste it into your "real" project in the Form Load event (or where ever it needs to be) and you've got what you need.
 
oh yeah...forgot to add...that's what I did to get the previous lines of code :) You may need to do some tweaking as far as adding references, declaring variables etc...but the compiler will tell you what it wants.
 
It works!
Thanks a lot macleod1021 4ur help
 
Any time. Just remember the little trick of keeping a test project available. It's saved me hours of research in the past. You can also learn a lot about how bindings and other behind the scenes referencing works. Great learning tool :)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top