473,320 Members | 2,003 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,320 software developers and data experts.

IExtenderProvider + Verbs = Error (Specified Cast Is Not Valid)

Hello folks,
First sorry my bad english.
I will try to implement a IExtenderProvider + Verbs (Designer). When
compile tha follow code its compile fine, but whem drag resulting
componet under form i gain a error: Specified Cast Is Not Valid :(

Code.

#Region "NameSpaces Area"

Imports System.ComponentModel
Imports System.Drawing
Imports System.Windows.Forms

Imports System.Windows.Forms.Design
Imports System.ComponentModel.Design

#End Region

<Designer(GetType(ClickEventProviderDesigner)),
ProvideProperty("MenuItem", GetType(ToolBarButton)), _
Description("Associa um evento de Click a um ToolBarButton."), _
Category("Eventos")> _
Public Class ClickEventProvider
Inherits Component
Implements IExtenderProvider

Private _Collection As New Hashtable()

#Region "Implements Area"

Public Function CanExtend(ByVal Extendee As Object) As Boolean _
Implements IExtenderProvider.CanExtend
' Habilita a funcionalidade somente para objetos ToolBarButton
Return TypeOf Extendee Is ToolBarButton

End Function

#End Region

#Region "ProvideProperty Area"

Public Function GetMenuItem(ByVal Button As ToolBarButton) As
MenuItem
' Retorna o objeto extendido caso exista na Collection. (
Run-Time )
If (_Collection.Contains(Button)) Then
Return CType(_Collection(Button), MenuItem)
Else
Return Nothing
End If

End Function

Public Sub SetMenuItem(ByVal Button As ToolBarButton, ByVal Item
As MenuItem)
' Param Button: Informa o botao que disparara o evento
' Param Item : Informa qual MenuItem devera ser chamado ao
clicar.

' Caso nao tenha um Item associado sai do metodo
If Item Is Nothing Then
' Eh preciso remover o Handler ou o evento sera disparado
duas vezes ;-}
RemoveHandler Button.Parent.ButtonClick, AddressOf
ToolbarHandler
Exit Sub
End If

' Caso o botao ja esteja contido na Collection (_Collection) o
mesmo sera alterado
' caso ainda nao esteja na Collection sera adicionado
If (_Collection.Contains(Button)) Then
_Collection(Button) = Item
Else
_Collection.Add(Button, Item)
AddHandler Button.Parent.ButtonClick, AddressOf
ToolbarHandler
End If

End Sub

#End Region

#Region "Private Methods"

Private Sub ToolbarHandler(ByVal Sender As Object, ByVal e As
ToolBarButtonClickEventArgs)

If (_Collection.Contains(e.Button)) Then
' Recupera o MenuItem associado ao botao e "dispara" o
click
CType(_Collection(e.Button), MenuItem).PerformClick()
End If

End Sub

#End Region
End Class

Public Class ClickEventProviderDesigner
Inherits ControlDesigner

Public Overrides ReadOnly Property Verbs() As
DesignerVerbCollection
Get
Return New DesignerVerbCollection(New DesignerVerb() {New
DesignerVerb("About", AddressOf AboutHandler)})
End Get
End Property

Private Sub AboutHandler(ByVal sender As Object, ByVal e As
System.EventArgs)

Dim About As String = _
"ToolBarButton Click Event Provider." & vbCrLf & _
"Copyright © 2003-2004." & _
"All Rights Reserved." & vbCrLf & _
"Genival Pereira de Carvalho."

MessageBox.Show(About, "About", _
MessageBoxButtons.OK, MessageBoxIcon.Information)

End Sub

End Class

Regards
Carvalho Genival
Japan
Nov 20 '05 #1
0 1857

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

Similar topics

1
by: Ron Holmes | last post by:
I posted this question on the Crystal Reports Support site and I am still waiting for an answer. Using Crystal Reports 9.0 Developer Full edition: My Crystal report .RPT file has a Picture box...
13
by: LL | last post by:
Hi, How to fix this problem: Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error...
5
by: .Net Sports | last post by:
I have a datagrid codebehind script that takes data from sql dbase and displays it in a footer row as a total. One column has amount_dollars (which works fine), while another has new sales (which...
8
by: Razak | last post by:
Hi, I have a class which basically do Impersonation in my web application. From MS KB sample:- ++++++++++++++++++++code starts Dim impersonationContext As...
1
by: .Net Sports | last post by:
I have a datagrid codebehind script that takes data from sql dbase and displays it in a footer row as a total. One column has amount_dollars (which works fine), while another has new sales (which...
0
by: kcm | last post by:
Hello all, Not sure if this is the right place to post this. I ran up the samples for adventureworks for MSSQL2005. I setup the shop front. The web site is up. But when I try to register a new...
1
vinci
by: vinci | last post by:
Please help me out... i only have two weeks to do it... here is my code: Dim ex As New Object Dim wb As Excel.Workbook Dim sheet As Excel.Worksheet
3
by: =?Utf-8?B?UGF1bCBQcmV3ZXR0?= | last post by:
I'm attempting to use LINQ to insert a record into a child table and I'm receiving a "Specified cast is not valid" error that has something to do w/ the keys involved. The stack trace is: ...
2
by: vinrin | last post by:
Thank for your answer. :-) call CheckEmptyNode (treeview) public void CheckEmptyNode( Object N ) { Microsoft.Web.UI.WebControls.TreeNode menuNode = null; ...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
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: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

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.