?
Solved

public property combobox

Posted on 2005-05-10
5
Medium Priority
?
249 Views
Last Modified: 2012-05-05
Hello,
I am using a public property function for my user control and i am wondering how i can make it like a combobox in the property window.  Im used to the string/integer function but not the combobox part.  Here is what im used to:

   Public Property WITitle() As String
        Get
            Return grbWaffleIron.Text
        End Get
        Set(ByVal Value As String)
            grbWaffleIron.Text = Value
        End Set
    End Property

What i would like to have is something like this:

    Public Property Port() As ComboBox
        Get
             Return port
        End Get
        Set(ByVal Value As ComboBox)
             port = value
        End Set
    End Property

How do i set the combobox choices and then return the correct one?  thanks!

Kevin
0
Comment
Question by:kevinmeredith
  • 2
  • 2
5 Comments
 
LVL 64

Expert Comment

by:Fernando Soto
ID: 13974159
I do not know why you would want to do something like this but who am I to stiful the imagination. So here is the code.

Imports System.Environment

Private _comboObj As New ComboBox

Public Property ComboObj() As ComboBox
    Get
        Return _comboObj
    End Get
    Set(ByVal Value As ComboBox)
        _comboObj = Value
    End Set
End Property

Private Sub btnAdd_Click(ByVal sender As Object, _
    ByVal e As System.EventArgs) Handles btnAdd.Click

    If txtName.Text Is Nothing Then
        Return
    End If

    Dim tempCombo As ComboBox

    tempCombo = ComboObj
    tempCombo.Items.Add(txtName.Text.ToString())
    ComboObj = tempCombo

    txtName.Text = Nothing

End Sub

Private Sub btnDisplayList_Click(ByVal sender As Object, _
    ByVal e As System.EventArgs) Handles btnDisplayList.Click

    Dim tempCombo As ComboBox
    Dim element As String
    Dim message As String

    tempCombo = ComboObj

    For Each element In tempCombo.Items
        message &= element & NewLine
    Next

    MessageBox.Show(message, "ComboBox List")

End Sub
0
 
LVL 64

Expert Comment

by:Fernando Soto
ID: 13974193
That should have been stifle
0
 
LVL 9

Accepted Solution

by:
checoo earned 1500 total points
ID: 13974853
the easier option is to use an enum containing the list of values you wnat displayed in the combobox

    Public Enum myValues
        one = 1
        two = 2
    End Enum

and then declare your property as

   Public Property WITitle() As myValues
        Get
            'write your processing code here
        End Get
        Set(ByVal Value As String)
            'write your processing code here
        End Set
    End Property

this will cause the above property to appear as combobox in the property grid
0
 
LVL 9

Expert Comment

by:checoo
ID: 13974895
Other than the simple way mentioned in my solution above, If you want a more sophisticated editior to be accessible from the property grid then you will have to implement your own UIType editor, check MSDN for the same or check out this link

http://msdn.microsoft.com/library/default.asp?url=/library/en- us/cpref/html/frlrfsystemdrawingdesignuitypeeditorclasstopic.asp
0
 

Author Comment

by:kevinmeredith
ID: 13978345
FernandoSoto,
thanks for the help.  for some reason though it won't let me choose from properties window what i put into the item list.  they show up when i expand the combobox properties but i cannot choose it.  any ideas on why?  

I like your enum idea checoo.  I think I will go with that.  thanks guys!
0

Featured Post

Independent Software Vendors: 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!

Question has a verified solution.

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

Microsoft Reports are based on a report definition, which is an XML file that describes data and layout for the report, with a different extension. You can create a client-side report definition language (*.rdlc) file with Visual Studio, and build g…
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…
Look below the covers at a subform control , and the form that is inside it. Explore properties and see how easy it is to aggregate, get statistics, and synchronize results for your data. A Microsoft Access subform is used to show relevant calcul…
Is your OST file inaccessible, Need to transfer OST file from one computer to another? Want to convert OST file to PST? If the answer to any of the above question is yes, then look no further. With the help of Stellar OST to PST Converter, you can e…
Suggested Courses

621 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