Solved

Displaying property values in IDE

Posted on 2004-09-19
6
191 Views
Last Modified: 2010-04-23
Hi there.

I am creating an inherited control containing a property named InputDataType which denotes what type of data the user will by allowed to type in. However, I want this property to have the predefined "String","Integer","Decimal" values in the IDE, thing which doesn't happen with the string type (happens with types such as boolean that have predefined values). I suppose I have to create a class, array, collection or something but I have been unable to find how to do it. Here is my code:

Private strInputDataType As String = "String"

Public Property InputDataType() As String
Get
Return strInputDataType
End Get
Set(ByVal Value As String)
Select Case Value
Case "String", "Integer", "Decimal"
strInputDataType = Value
Case Else
strInputDataType = "String"
End Select
End Set
End Property

What must I do in order for the "String", "Integer" and "Decimal" values to be displayed in the IDE in the property's value field?

Thanks...
0
Comment
Question by:acicovic
  • 3
  • 3
6 Comments
 
LVL 4

Accepted Solution

by:
vigrid earned 100 total points
ID: 12096416
Simple. Use enumerations

Enum DataType
  String,
  Integer,
  Decimal
End Enum

And use DataType enumeration in place of your strings. You should have access to the type in the designer in a way you wanted.

HTH
0
 
LVL 2

Author Comment

by:acicovic
ID: 12096774
Hi there.

I tried, but I don't seem to be able to achieve it.  The only change is that I have to type 0 (for str), 1 (for int) and 2 (for dec) (which should be the inverse if I want it to be user friendly).  In addition, the numbers do *not* appear in a list.  My code:

    Enum DataType
        Str = 0
        Int = 1
        Dec = 2
    End Enum

    Public Property InputDataType() As DataType
        Get
            Return strInputDataType
        End Get
        Set(ByVal Value As DataType)
            Select Case Value
                Case DataType.Str, DataType.Int, DataType.Dec
                    strInputDataType = Value
                Case Else
                    strInputDataType = DataType.Str
            End Select
        End Set
    End Property

What am I doing wrong?
0
 
LVL 2

Author Comment

by:acicovic
ID: 12096781
forgot to mention that below the Enum I have the following line:

Private strInputDataType As DataType
0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
LVL 4

Expert Comment

by:vigrid
ID: 12096986
Public Class UserControl1
      Inherits UserControl

      ' Methods
      Public Sub New()
      Protected Overrides Sub Dispose(ByVal disposing As Boolean)
      Private Sub InitializeComponent()

      ' Properties
      Public Property InputDataType As DataType

      ' Fields
      Private components As Container
      Private m_type As DataType

      ' Nested Types
      Public Enum DataType
            ' Fields
            [Decimal] = 1
            [Integer] = 0
            [String] = 2
      End Enum

      Public Property InputDataType As DataType
            Get
                  Return Me.m_type
            End Get
            Set(ByVal value As DataType)
                  Me.m_type = value
            End Set
      End Property
End Class

0
 
LVL 4

Expert Comment

by:vigrid
ID: 12096993
Very fast example. I made it in C#, compiled it and decompiled it in .NET Reflector, so the code may seem funny at first look, but the essential functionality is there. I don't know VB.NET, so I'm helping you out with my C# experience. HTH
0
 
LVL 2

Author Comment

by:acicovic
ID: 12105705
Hi there.

I Got it working, although I cannot understand why it didn't work in the first place.  Here's the code for anyone who's interested:

    Enum DataType As Byte
        [Decimal]
        [Integer]
        [String]
    End Enum

    Private dtInputDataType As DataType

    Public Property InputDataType() As DataType
        Get
            Return dtInputDataType
        End Get
        Set(ByVal Value As DataType)
            Select Case Value
                Case DataType.String, DataType.Integer, DataType.Decimal
                    dtInputDataType = Value
                Case Else
                    dtInputDataType = DataType.String
            End Select
        End Set
    End Property
0

Featured Post

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

Article by: jpaulino
XML Literals are a great way to handle XML files and the community doesn’t use it as much as it should.  An XML Literal is like a String (http://msdn.microsoft.com/en-us/library/system.string.aspx) Literal, only instead of starting and ending with w…
Introduction As chip makers focus on adding processor cores over increasing clock speed, developers need to utilize the features of modern CPUs.  One of the ways we can do this is by implementing parallel algorithms in our software.   One recent…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

705 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now