473,799 Members | 3,093 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

on click event for item on a dropdown button control on toolbar

Somehow I'm just missing something.

I don't know how to catch when a user clicks on an item in a dropdown list
for a dropdown style button on a toolbar.

I create a new app. Form1. Add a toolbar. Add a button and make it's
style dropdown. In the code I create a contextmenu and add three items.

This is all fine. But when I click on one of the menu items I can't figure
out how to know it's been clicked and what menu item it is.

Here's the test code:

Public Class Form1

Inherits System.Windows. Forms.Form

#Region " Windows Form Designer generated code "

Public Sub New()

MyBase.New()

'This call is required by the Windows Form Designer.

InitializeCompo nent()

'Add any initialization after the InitializeCompo nent() call

End Sub

'Form overrides dispose to clean up the component list.

Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)

If disposing Then

If Not (components Is Nothing) Then

components.Disp ose()

End If

End If

MyBase.Dispose( disposing)

End Sub

'Required by the Windows Form Designer

Private components As System.Componen tModel.IContain er

'NOTE: The following procedure is required by the Windows Form Designer

'It can be modified using the Windows Form Designer.

'Do not modify it using the code editor.

Friend WithEvents ToolBar1 As System.Windows. Forms.ToolBar

Friend WithEvents ToolBarButton1 As System.Windows. Forms.ToolBarBu tton

<System.Diagnos tics.DebuggerSt epThrough()> Private Sub InitializeCompo nent()

Me.ToolBar1 = New System.Windows. Forms.ToolBar

Me.ToolBarButto n1 = New System.Windows. Forms.ToolBarBu tton

Me.SuspendLayou t()

'

'ToolBar1

'

Me.ToolBar1.But tons.AddRange(N ew System.Windows. Forms.ToolBarBu tton()
{Me.ToolBarButt on1})

Me.ToolBar1.Dro pDownArrows = True

Me.ToolBar1.Loc ation = New System.Drawing. Point(0, 0)

Me.ToolBar1.Nam e = "ToolBar1"

Me.ToolBar1.Sho wToolTips = True

Me.ToolBar1.Siz e = New System.Drawing. Size(456, 42)

Me.ToolBar1.Tab Index = 0

'

'ToolBarButton1

'

Me.ToolBarButto n1.Style =
System.Windows. Forms.ToolBarBu ttonStyle.DropD ownButton

Me.ToolBarButto n1.Text = "test"

'

'Form1

'

Me.AutoScaleBas eSize = New System.Drawing. Size(5, 13)

Me.ClientSize = New System.Drawing. Size(456, 334)

Me.Controls.Add (Me.ToolBar1)

Me.Name = "Form1"

Me.Text = "Form1"

Me.ResumeLayout (False)

End Sub

#End Region

Private Sub Form1_Load(ByVa l sender As Object, ByVal e As System.EventArg s)
Handles MyBase.Load

Dim cm As New ContextMenu

cm.MenuItems.Ad d("one")

cm.MenuItems.Ad d("two")

ToolBar1.Button s(0).DropDownMe nu = cm

End Sub

End Class
Nov 21 '05 #1
1 3561
Hi Curtis
What you should be handing is the MenuItem click event , you could create
a separate handler that handles the click on each of the menu items of
your context menu , your handler should be something like that
Private Sub MenuItem1_Click (ByVal sender As System.Object, ByVal e
As System.EventArg s) Handles MenuItem1.Click
MessageBox.Show ("Source Control: " & CType(sender,
MenuItem).Paren t.GetContextMen u().SourceContr ol.ToString)
'If ContextMenu1.So urceControl Is Nothing Then
'MessageBox.Sho w("Yes")
'Else
' MessageBox.Show (ContextMenu1.S ourceControl.Na me)
'End If

End Sub
in this example you see you can get also the source control ( if you are
using the menu with more than one control) . you would know under with
control this item was clicked
Hope this helps

Mohamed Mahfouz
MEA Developer Support Center
ITworx on behalf of Microsoft EMEA GTSC

Nov 21 '05 #2

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

Similar topics

0
1632
by: Philip Townsend | last post by:
I have a datagrid that contains a dropdown list that is part of an EditItemTemplate. I need to run some code when the dropdown list builds in order to preselect an item in the list. Preselecting the item is not the problem. The problem is that the dropdown object is not instantiated at the point at which the Edit button is clicked, or at any other obvious step in the process. In other words, when a user clicks the Edit (EditCommand)...
2
11611
by: Niclas Lindblom | last post by:
Hi, I have a datagrid with linkbuttons. I would like to catch the click event when a link button has been clicked and use the string from the text value of the link button in a clientside Java script. Is this possible or should I look for other ways of achieving this ? Regards Niclas
6
1379
by: WebMatrix | last post by:
Hello, Here's the situation (I'll try to be brief as possible) I am working on the control which is created dynamically based on XML string. This control consists of a table with number of rows with 3 columns; TextBox, dropdown and a button ("Delete" button) in each column. Also there's one button at the bottom of the table that allows users to add more rows. So more controls will be added programmatically as user adds more rows. What's...
24
7708
by: Charles Law | last post by:
When I click a button I don't want the click event to fire. Is this possible? In fact, what I would really like is to be able to intercept the click event, perform some action, and then prevent the click from passing through to the button. Any help or suggestions much appreciated. Charles
41
4331
by: JohnR | last post by:
In it's simplest form, assume that I have created a usercontrol, WSToolBarButton that contains a button. I would like to eventually create copies of WSToolBarButton dynamically at run time based on some initialization information obtained elsewhere. Basically, I'm going to create my own dynamic toolbar where the toolbarbuttons can change. I'm not using the VB toolbar because of limitations in changing things like backcolor (I can't get...
21
8157
by: Ben | last post by:
Hello I have frames set up in an asp.net application and need one frame to refresh another. Seeing as events need to be registered at the time the page is sent from the server, I was wondering if I could place a hidden button in a frame that would have the attribute to refresh the other. I would need code to "invoke" the onclick event (ie i need code to click the button). is this possible? thanks.
0
1219
by: Shashank | last post by:
Hi all, I have made a toolbar in c# using toolstrip control. I am using xml file to generate menu at runtime and then binding it to the dropdown button. My problem is that when I click the dropdown button for the first time the menu, the dropdown doesn't appear. On the second and all subsequent clicks, the dropdown is visible and is behaving normally. Can anyone drag me out of this problem???????
0
2043
by: nraji | last post by:
hi, I have designed a web part using VS 2003 (Web control library template). I need to publish that in share point. Its not like drag and drop the things from toolbar. Every thing I need to do in code behind side. I have a button and text box Button Id: btnSearch TextBox id: txtSearch
2
1374
by: elijahs | last post by:
This seems like an obvious one but it has me stumped. I have a complex form with a bunch of databound grids and textbox controls. There is a MainMenu control, and a toolbar control with shortcuts to some of the most common commands - for instance, Save. When I click on a toolbar control, I can catch the ItemClick event and do a toolbar.Focus call to switch focus to the toolbar, thereby pulling focus from whatever input control was...
0
9685
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9538
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10249
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10219
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10025
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9068
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7563
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5584
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3755
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.