Solved

Adding two tags to Menuitems with ExtenderProvider

Posted on 2004-08-31
5
499 Views
Last Modified: 2008-01-09
The following code, found on the net, adds a tag to each MenuItem. Works well. But...I want to add ANOTHER tag, call it Tag2. How?
--------


Imports System.ComponentModel
Imports System.Windows.Forms

<ProvideProperty("Tag", GetType(MenuItem))> _
Public Class MenuTagger
    Inherits Component
    Implements IExtenderProvider

#Region "Extender Implementation "

    Private Props As Hashtable = New Hashtable()

    Public Function CanExtend(ByVal Ctl As Object) As Boolean Implements IExtenderProvider.CanExtend
        If TypeOf Ctl Is MenuItem Then Return True
    End Function

    <ExtenderProvidedProperty(), Category("Appearance"), DefaultValue(GetType(String), Nothing)> _
    Public Function GetTag(ByVal target As MenuItem) As String
        If Props.Contains(target) Then
            Return CType(Props(target), String)
        End If
        Props.Add(target, Nothing)
    End Function

    Public Sub SetTag(ByVal target As MenuItem, ByVal value As String)
        If Props.Contains(target) Then
            Props.Remove(target)
        End If
        Props.Add(target, value)
    End Sub

#End Region

End Class
0
Comment
Question by:rdavis101
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
5 Comments
 
LVL 25

Accepted Solution

by:
RonaldBiemans earned 125 total points
ID: 11951358
Can't you simply do this

Option Strict Off
Option Explicit On

Imports Microsoft.VisualBasic
Imports System
Imports System.ComponentModel
Imports System.Windows.Forms

<ProvideProperty("Tag", GetType(MenuItem))> _
Public Class MenuTagger
    Inherits Component
    Implements IExtenderProvider

#Region "Extender Implementation "

    Private Props As Hashtable = New Hashtable
    Private Props2 As Hashtable = New Hashtable

    Public Function CanExtend(ByVal Ctl As Object) As Boolean Implements IExtenderProvider.CanExtend
        If TypeOf Ctl Is MenuItem Then Return True
    End Function

    <ExtenderProvidedProperty(), Category("Appearance"), DefaultValue(GetType(String), Nothing)> _
    Public Function GetTag(ByVal target As MenuItem) As String
        If Props.Contains(target) Then
            Return CType(Props(target), String)
        End If
        Props.Add(target, Nothing)
    End Function

    Public Sub SetTag(ByVal target As MenuItem, ByVal value As String)
        If Props.Contains(target) Then
            Props.Remove(target)
        End If
        Props.Add(target, value)
    End Sub

    Public Function GetTag2(ByVal target As MenuItem) As String
        If Props2.Contains(target) Then
            Return CType(Props2(target), String)
        End If
        Props2.Add(target, Nothing)
    End Function

    Public Sub SetTag2(ByVal target As MenuItem, ByVal value As String)
        If Props2.Contains(target) Then
            Props2.Remove(target)
        End If
        Props2.Add(target, value)
    End Sub

#End Region
0
 

Author Comment

by:rdavis101
ID: 11951963
Did you test this?  I'm in the process of testing it now.

Question: WHy does the line

<ProvideProperty("Tag", GetType(MenuItem))> _

Appear only once?
0
 
LVL 25

Expert Comment

by:RonaldBiemans
ID: 11952178
Yes I did and it worked. The provideproperty and ExtenderProvidedProperty are things you will see in the property window if you decide to create your own "mainmenu" control
0
 
LVL 25

Expert Comment

by:RonaldBiemans
ID: 11952197
look here for a better explaination

http://www.devx.com/dotnet/Article/21462/1763/page/2
0
 

Author Comment

by:rdavis101
ID: 11952469
Dude, thanks so much! :)

Roger
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This tutorial demonstrates one way to create an application that runs without any Forms but still has a GUI presence via an Icon in the System Tray. The magic lies in Inheriting from the ApplicationContext Class and passing that to Application.Ru…
Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…
Are you ready to implement Active Directory best practices without reading 300+ pages? You're in luck. In this webinar hosted by Skyport Systems, you gain insight into Microsoft's latest comprehensive guide, with tips on the best and easiest way…

756 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question