User Control Property

  • Thread starter Thread starter David Gacek
  • Start date Start date
D

David Gacek

Anyone know how to ... make a user control property that shows up in the
property pages and allows one to select a value from a set of values ?
like a combobox for example ?
 
Hello David,

Very simple. Just put attribute to the property you want to be in property
window.
<System.ComponentModel.Category("MyApp")> _

"MyApp" can your name of your application. It shows up when you order the
properties in categorized view.
 
I'm not sure i understand ... will that allow me to make a list of stuff i
want the user to select from the property window ?
 
Declare the input value of the property as an enumerated value...

Public Enum People
Ann
Bill
Carter
David
End Enum

<Browsable(False)> Public Property UserName() As People
Get
Return m_userName

End Get

Set(ByValue value as People)
m_userName = value

End Set

End Property

A

End Property
 
David,

First the sample what I think you are asking for, when this is not the
answer ask more?

Just make a property
\\\
Private mDavid As Integer
Friend Property David() As Integer
Get
Return mDavid
End Get
Set(ByVal Value As Integer)
mDavid = Value
End Set
End Property
///

Most of it will be made automaticly when you type in
Friend Property Dave() As Integer

I hope this helps?

Cor
 
Thanks Ray you are the closes to what i was looking for however when i try
to use an enum i get constact expression required
I already tried that earlier with enum and tried an alternate way. still
working on this .
 
Is there any other way to what Ray illustrated without using enum ?
 
I'm trying to call a function for a the enum thats why i'm getting the
error.
How else can i acheive the same result with out using an enum ?
 
i want to stay away from the enum because the values i would be adding to
the property page are not contants.
 
David,

Although I readed your question not right and in the same time did not see
the message from Ray, would I have made it the same as Ray, however I
thought I sand you a message 2 hours ago that by incident is the answer on
your question as it is now.

I hope that helps?

Cor
 
try that in better english or after some sleep :) cause i couldn't
understand it.

Yes it still don't work how i want it ...
all i would like to do is have the user select from a group a values and i
can not use an enum because the values that would be used are not constants.
So is there any other way doto this with out an enum like in Rays sample. ?
 
David,
try that in better english or after some sleep :) cause i couldn't
understand it

You can probably ask this better to other people however I try
Yes it still don't work how i want it ...

My problem is that it still does not work, as I want it.
all i would like to do is have the user select from a group a values and i
can not use an enum because the values that would be used are not
constants.

All that I want to do is creating the possibility that the user can select
from a selection in a property box. I am not able to use the "enumeration"
because of the fact that the values that will be used are not constant.
So is there any other way doto this with out an enum like in Rays sample.
?
Therefore is my question, is there any other way to do this without that I
need an "enumeration" as Ray shows in his sample?

I hope this fits your question?

Cor
 
I guess then I am having a difficult time trying to determine what you are
exactly trying to do then.

I get the feeling that you want to be able to (at design time) crate a list
of values that the user can select in the property window?

Besides maybe the way that choosing the data sources when doing data binding
I am not sure how else this could be used. I have to admit that I am not
sure how to do what you want aside form maybe building an enum on the fly or
something.

Perhaps is you give what an example (maybe in pseudo code or something) as
to how you would want to use this we might be able to help out.

Perhaps is you base the property value on something like an arraylist.
 
What i want to do is put all the installled printers into a drop down list
/ combobox ... property box so the user can select one.
Dim objPrint As New System.Drawing.Printing.PrinterSettings

Dim strItem As String

Dim strPrinters As String

For Each strItem In objPrint.InstalledPrinters

strPrinters &= strItem & vbCrLf

next
 
Anyone know how to ... make a user control property that shows up in the
property pages and allows one to select a value from a set of values ?
like a combobox for example ?

If I understand correctly, you want a custom property that shows up in the
PropertyGrid as a drop down and you want to customize the list of available
choices.

In order to do this, create a class that inherits from StringConverter and
then override the GetStandardValues method to return an instance of a
StandardValuesCollection object with the correct values. Something similar
to this (watch for word wrap):


'CODE BEGINS HERE
Public Class MyCustomList
Inherits StringConverter

Public Overloads Overrides Function GetStandardValues(ByVal context As
System.ComponentModel.ITypeDescriptorContext) As
System.ComponentModel.TypeConverter.StandardValuesCollection

Dim alMyList As New System.Collections.ArrayList
alMyList.Add("Item 1")
alMyList.Add("Item 2")
alMyList.Add("Item 3")

'Add other values to the array list here

Return New StandardValuesCollection(alMyList)
End Function

Public Overloads Overrides Function GetStandardValuesExclusive(ByVal
context As System.ComponentModel.ITypeDescriptorContext) As Boolean
Return True
End Function

Public Overloads Overrides Function GetStandardValuesSupported(ByVal
context As System.ComponentModel.ITypeDescriptorContext) As Boolean
Return True
End Function
End Class
'CODE ENDS HERE

Then to use it with your property, you need to add the TypeConverter
Attribute to your property:

Private m_MyItem As String

<TypeConverter(GetType(MyCustomList))> _
Public Property MyItem As String
Get
Return m_MyItem
End Get
Set(ByVal Value As String)
m_MyItem = Value
End Set
End Property


Hope this helps

--
Chris

dunawayc[AT]sbcglobal_lunchmeat_[DOT]net

To send me an E-mail, remove the "[", "]", underscores ,lunchmeat, and
replace certain words in my E-Mail address.
 
Wow Chris

That is exactly what i was looking for !
I had implemented a totally different fix to the prob, but this is what i
had imagined from the get go.

Thanks

Chris Dunaway said:
Anyone know how to ... make a user control property that shows up in the
property pages and allows one to select a value from a set of values ?
like a combobox for example ?

If I understand correctly, you want a custom property that shows up in the
PropertyGrid as a drop down and you want to customize the list of available
choices.

In order to do this, create a class that inherits from StringConverter and
then override the GetStandardValues method to return an instance of a
StandardValuesCollection object with the correct values. Something similar
to this (watch for word wrap):


'CODE BEGINS HERE
Public Class MyCustomList
Inherits StringConverter

Public Overloads Overrides Function GetStandardValues(ByVal context As
System.ComponentModel.ITypeDescriptorContext) As
System.ComponentModel.TypeConverter.StandardValuesCollection

Dim alMyList As New System.Collections.ArrayList
alMyList.Add("Item 1")
alMyList.Add("Item 2")
alMyList.Add("Item 3")

'Add other values to the array list here

Return New StandardValuesCollection(alMyList)
End Function

Public Overloads Overrides Function GetStandardValuesExclusive(ByVal
context As System.ComponentModel.ITypeDescriptorContext) As Boolean
Return True
End Function

Public Overloads Overrides Function GetStandardValuesSupported(ByVal
context As System.ComponentModel.ITypeDescriptorContext) As Boolean
Return True
End Function
End Class
'CODE ENDS HERE

Then to use it with your property, you need to add the TypeConverter
Attribute to your property:

Private m_MyItem As String

<TypeConverter(GetType(MyCustomList))> _
Public Property MyItem As String
Get
Return m_MyItem
End Get
Set(ByVal Value As String)
m_MyItem = Value
End Set
End Property


Hope this helps

--
Chris

dunawayc[AT]sbcglobal_lunchmeat_[DOT]net

To send me an E-mail, remove the "[", "]", underscores ,lunchmeat, and
replace certain words in my E-Mail address.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top