Solved

Displaying property values in IDE

Posted on 2004-09-19
6
229 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
[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
  • 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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering 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

It’s quite interesting for me as I worked with Excel using vb.net for some time. Here are some topics which I know want to share with others whom this might help. First of all if you are working with Excel then you need to Download the Following …
Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

735 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