Click here to Skip to main content
Click here to Skip to main content
Articles » Languages » VB.NET » General » Downloads
 
Add your own
alternative version
Go to top

Using PropertyGrid Part-I

, 3 Feb 2003
Explains about PropertyGrid and how to use, with detailed examples
''' Developed by : Sreenivas Vemulapalli
''' vemvas@yahoo 
''' Date: 08/15/2002
'''
Imports System.ComponentModel
Imports System.ComponentModel.Design.Serialization
'''
<TypeConverter(GetType(ApplicationVersionConverter))> _
Public Class ApplicationVersion
    '''
    Private _Major As Short
    Private _Minor As Short
    Private _Build As Short
    Private _Private As Short
    '''
    <DescriptionAttribute("Set the major part of version number")> _
        Public Property Major() As Short
        Get
            Return _Major
        End Get
        Set(ByVal Value As Short)
            _Major = Value
        End Set
    End Property
    '''
    <DescriptionAttribute("Set the minor part of version number")> _
    Public Property Minor() As Short
        Get
            Return _Minor
        End Get
        Set(ByVal Value As Short)
            Me._Minor = Value
        End Set
    End Property
    '''
    <DescriptionAttribute("Set the build part of version number")> _
    Public Property Build() As Short
        Get
            Return _Build
        End Get
        Set(ByVal Value As Short)
            Me._Build = Value
        End Set
    End Property
    '''
    <DescriptionAttribute("Set the private part of version number")> _
    Public Property [Private]() As Short
        Get
            Return _Private
        End Get
        Set(ByVal Value As Short)
            Me._Private = Value
        End Set
    End Property
    '''
End Class

Friend Class ApplicationVersionConverter : Inherits ExpandableObjectConverter
    '''
    Public Overloads Overrides Function CanConvertFrom(ByVal context As System.ComponentModel.ITypeDescriptorContext, ByVal sourceType As System.Type) As Boolean
        If (sourceType Is GetType(String)) Then
            Return True
        End If
        Return MyBase.CanConvertFrom(context, sourceType)
    End Function

    Public Overloads Overrides Function ConvertFrom(ByVal context As System.ComponentModel.ITypeDescriptorContext, ByVal culture As System.Globalization.CultureInfo, ByVal value As Object) As Object
        If TypeOf value Is String Then
            Try
                Dim s As String = CType(value, String)
                Dim versionParts() As String
                Dim VersionString As String = ""
                versionParts = Split(s, ".")
                If Not IsNothing(versionParts) Then
                    Dim _ApplicationVersion As ApplicationVersion = New ApplicationVersion()
                    If Not IsNothing(versionParts(0)) Then _ApplicationVersion.Major = versionParts(0)
                    If Not IsNothing(versionParts(1)) Then _ApplicationVersion.Minor = versionParts(1)
                    If Not IsNothing(versionParts(2)) Then _ApplicationVersion.Build = versionParts(2)
                    If Not IsNothing(versionParts(3)) Then _ApplicationVersion.Private = versionParts(3)
                End If
            Catch ex As Exception
                Throw New ArgumentException("Can not convert '" + value + "' to type ApplicationVersion")
            End Try
        End If
        Return MyBase.ConvertFrom(context, culture, value)
    End Function

    Public Overloads Overrides Function ConvertTo(ByVal context As System.ComponentModel.ITypeDescriptorContext, ByVal culture As System.Globalization.CultureInfo, ByVal value As Object, ByVal destinationType As System.Type) As Object
        If (destinationType Is GetType(System.String) AndAlso TypeOf value Is ApplicationVersion) Then
            Dim _ApplicationVersion As ApplicationVersion = CType(value, ApplicationVersion)
            ' build the string as "Major.Minor.Build.Private" 
            Return _ApplicationVersion.Major & "." & _ApplicationVersion.Minor & "." & _ApplicationVersion.Build & "." & _ApplicationVersion.Private
        End If
        Return MyBase.ConvertTo(context, culture, value, destinationType)
    End Function

    Public Overloads Overrides Function CanConvertTo(ByVal context As System.ComponentModel.ITypeDescriptorContext, ByVal destinationType As System.Type) As Boolean
        If (destinationType Is GetType(ApplicationVersion)) Then
            Return True
        End If
        Return MyBase.CanConvertFrom(context, destinationType)
    End Function
End Class

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here

Share

About the Author

Sreenivas Vemulapalli
Web Developer
United States United States
Working as consultant in Client/server,Web Development, Automation areas using C#,Vb,Vb.net,Asp.net,Sql Server,Xml,Html&Dhtml etc..
Looking for a challenging project in .NET

| Advertise | Privacy | Mobile
Web02 | 2.8.140916.1 | Last Updated 4 Feb 2003
Article Copyright 2002 by Sreenivas Vemulapalli
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid