.NETGURU
Click Event Being Called Twice
Messages   Related Types
This message was discovered on microsoft.public.dotnet.framework.interop.

Post a new message to this list...

Josh Asbury
I am really struggling with something that is going on in an Excel menu
add-in that I have written ( Code snippets are below ) using Visual VB.net
2002. If a commandbar has the same caption as another commandbar elsewhere
in the menu structure, it calls both Click events and subsequently inserts
my custom text twice. Using the code below as an example, both DatesText(0)
and CaseDataDates are set to "Arrangement Date ( January 1, 2004 )". If I
choose one of these menu items, my code fires the Click events for both
CommandBarButtons and subsequently inserts my custom text
("%%=$MMP.CaseArrangementDate") twice.

The same thing was happening with DatesText(1) and
CaseDataDatesInsertText(1) until I set DatesText(0) to "Case Birth Date Day
( 01 )". At that point, only the click event for DatesTextMenuItem1 is
fired (as I wish and expect to happen).

Does anyone have any idea why this is happening and what I can do to fix it?
If I execute this code outside of an Add-in/Interop scenario, it works like
a champ. I'm relatively new to the .net world and Windows programming in
general (I'm a Java guy), so please slap me upside the head and show me the
err of my ways.

Thanks!
Josh

------------------- Declarations ----------------------
'Dates Menu
Private DatesText(1) As String
Private DatesInsertText(1) As String
Private MenuBarDatesCBC As CommandBarPopup
Private WithEvents DatesTextMenuItem0 As CommandBarButton
Private WithEvents DatesTextMenuItem0 As CommandBarButton

'Case Dates Menu
Private CaseDataDatesText(1) As String
Private CaseDataDatesInsertText(1) As String
Private MenuBarCaseDatesCBC As CommandBarPopup
Private WithEvents CaseDatesTextMenuItem0 As CommandBarButton

-------------------- Assignments and Menu Creations -----------------
DatesText(0) = "Arrangement Date ( January 1, 2004 )"
DatesText(1) = "Case Birth Date Day ( 01 )"

DatesInsertText(0) = "%%=$MMP.CaseArrangementDate"
DatesInsertText(1) = "%%=$MMP.CaseBirthDateDay"

'Add the Dates Menu
MenuBarDatesCBC = MenuBarItem.Controls.Add( _
MsoControlType.msoControlPopup, Temporary:=True)
MenuBarDatesCBC.Caption = "Dates"

DatesTextMenuItem0 = MenuBarDatesCBC.Controls.Add(msoControlButton)
With DatesTextMenuItem0
.Caption = DatesText(0)
.Style = msoButtonCaption
.Tag = DatesText(0)
.OnAction = "!<MMPExcelCOM.Connect>"
.Visible = True
End With

DatesTextMenuItem1 = MenuBarDatesCBC.Controls.Add(msoControlButton)
With DatesTextMenuItem1
.Caption = DatesText(1)
.Style = msoButtonCaption
.Tag = DatesText(1)
.OnAction = "!<MMPExcelCOM.Connect>"
.Visible = True
End With

CaseDataDatesText(0) = "Arrangement Date ( January 1, 2004 )"
CaseDataDatesText(1) = "Birth Date Day ( 01 )"

CaseDataDatesInsertText(6) = "%%=$MMP.CaseArrangementDate"
CaseDataDatesInsertText(7) = "%%=$MMP.CaseBirthDateDay"

CaseDatesTextMenuItem0 =
MenuBarCaseDatesCBC.Controls.Add(msoControlButton)
With CaseDatesTextMenuItem0
.Caption = CaseDataDatesText(0)
.Style = msoButtonCaption
.Tag = CaseDataDatesText(0)
.OnAction = "!<MMPExcelCOM.Connect>"
.Visible = True
End With

CaseDatesTextMenuItem0 =
MenuBarCaseDatesCBC.Controls.Add(msoControlButton)
With CaseDatesTextMenuItem0
.Caption = CaseDataDatesText(0)
.Style = msoButtonCaption
.Tag = CaseDataDatesText(0)
.OnAction = "!<MMPExcelCOM.Connect>"
.Visible = True
End With

---------------------------- Click
Events -------------------------------------------------
Private Sub DatesTextMenuItem0_Click(ByVal Ctrl As CommandBarButton,
ByRef CancelDefault As Boolean) Handles DatesTextMenuItem0.Click
MMPTag = applicationObject.ActiveCell()
MMPTag.Value2 = DatesInsertText(0)
End Sub

Private Sub DatesTextMenuItem1_Click(ByVal Ctrl As CommandBarButton,
ByRef CancelDefault As Boolean) Handles DatesTextMenuItem1.Click
MMPTag = applicationObject.ActiveCell()
MMPTag.Value2 = DatesInsertText(1)
End Sub

Private Sub CaseDatesTextMenuItem0_Click(ByVal Ctrl As
CommandBarButton, ByRef CancelDefault As Boolean) Handles
CaseDatesTextMenuItem0.Click
MMPTag = applicationObject.ActiveCell()
MMPTag.Value2 = CaseDataDatesInsertText(0)
End Sub

Private Sub CaseDatesTextMenuItem1_Click(ByVal Ctrl As
CommandBarButton, ByRef CancelDefault As Boolean) Handles
CaseDatesTextMenuItem1.Click
MMPTag = applicationObject.ActiveCell()
MMPTag.Value2 = CaseDataDatesInsertText(1)
End Sub

Reply to this message...
 
    
Josh Asbury
I resolved this issue. It turns out that this was occurring because my code
was setting the .Tag value to be the same, and subsequently causing the
Click events for both to fire. This is what I would consider a gotcha.

"Josh Asbury" <Click here to reveal e-mail address> wrote in message
news:Click here to reveal e-mail address...
[Original message clipped]

Reply to this message...
 
 




ExamGuru IT Solutions - .Net Guru is owned and operated by ExamGuru, Inc., the man behind .Net Guru. If you're in the market for bespoke software or software consultancy, why not get him and his highly trained team to help? - www.examguru.net/ITCertification
Ad


Need Dot Net Interview Questions?
Ask ExamGuru, Inc. for advice and help on Passing .Net Interviews
.Net Projects
Best-of-breed application framework for .NET projects, developed by ExamGuru, Inc. and ExamGuru IT
Free .net Help
Commission ExamGuru, Inc. and his team for your next bespoke software project
FogBUGZ
The only bug tracking system carefully crafted with one goal in mind: helping teams create great software.
Awesome Tools
If you don't know about these, you're missing out... IT Certification Questions
IT Interview Questions
Free Oracle 10g Training
MCSE Boortcamp
Cisco Study Guides
Cheap Study Guides
Exact Questions
Dot Net Interview Questions
Oracle OCP
Cheap Travel
Designer Perfumes - Wholesale Prices
Free Programming Tutorials
 
ExamGuru IT Solutions - .Net Guru is owned and operated by ExamGuru, Inc., the man behind .Net Guru. If you're in the market for bespoke software or software consultancy, why not get him and his highly trained team to help? - www.examguru.net/ITCertification
 Copyright © ExamGuru, Inc. 2001-2006
Contact Us - Terms of Use - Privacy Policy - www.dot-net-guru.com - www.examguru.net - www.oraclesource.net - www.itinterviews.net - www.examguru.net/ITCertification