Solved

Displaying property values in IDE

Posted on 2004-09-19
6
215 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
VMware Disaster Recovery and Data Protection

In this expert guide, you’ll learn about the components of a Modern Data Center. You will use cases for the value-added capabilities of Veeam®, including combining backup and replication for VMware disaster recovery and using replication for data center migration.

 
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

NAS Cloud Backup Strategies

This article explains backup scenarios when using network storage. We review the so-called “3-2-1 strategy” and summarize the methods you can use to send NAS data to the cloud

Question has a verified solution.

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

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…
Article by: Kraeven
Introduction Remote Share is a simple remote sharing tool, enabling you to see, add and remove remote or local shares. The application is written in VB.NET targeting the .NET framework 2.0. The source code and the compiled programs have been in…
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

822 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