Edit collection property from Property window...

N

nobody

If I've got a property on my web control that is a collection (of strings),
how can I have it allow the user to edit those strings through the property
window at design time?

The property on my webcontrol is defined as:
Private WithEvents m_Choices As ChoiceList
Property Choices() As ChoiceList
Get
Return m_Choices
End Get

Set(ByVal Value As ChoiceList)
m_Choices = Value
End Set
End Property

ChoiceList is defined as:
Public Class ChoiceList
Implements IEnumerable
Implements IEnumerator

Private m_Choices As New ArrayList
Private m_CurChoice As Integer

Public Event ChoicesChanged()

Public Sub New()
Me.Clear()
End Sub

Public Sub Clear()
Me.Reset()
m_Choices.Clear()
RaiseEvent ChoicesChanged()
End Sub

Public Function Add(ByVal Choice As String) As Integer
Dim Value As Integer
Value = m_Choices.Add(Choice)
RaiseEvent ChoicesChanged()
Return Value
End Function
...
End Class

Do I have to implement IList? The whole point of the class is to make the
collection typesafe. IList users Object which lets the user pass anything
in.
 
N

Natty Gur

Hi,

What about using the default string collection editor supplied with
visual studio. it should be use by default when you create property that
handle string collection.

Natty Gur[MVP]

blog : http://weblogs.asp.net/ngur
Mobile: +972-(0)58-888377
 
N

nobody

As my class was originally written (didn't implement any collection
interfaces), it showed up dimmed out in the property window. If I implement
the IList interface, it lets me click the ellipse button in the property
window, and it will let me add elements to the list, but it won't let me
edit the elements. This must be becase IList.Item(...) returns Object's,
not strings. I don't know how to work around this. For now, my collection
is editable only at runtime through code, which is ok with the client.
 
N

Natty Gur

Yes it all about Ilist. you can use StringCollection whuch support iList
and lomites to string elements.


[Bindable(true),
Category("natty"),
DefaultValue(""),
public System.Collections.Specialized.StringCollection Texts
{
get
{
return texts;
}

set
{
texts = value;
}
}

Natty Gur[MVP]

blog : http://weblogs.asp.net/ngur
Mobile: +972-(0)58-888377
 
N

nobody

Doh! Now why didn't I think to look in the System.Collections.Specialized
namespace? Thanks! :)
 
N

nobody

In the property window, when I click on the ellipse for my StringCollection
property, I get the window that lets you add and edit items in the
collection. But when I click on the "Add" button, I get "Constructor on
System.String not found."

Here's what I have in my class:
Private m_Choices As New Collections.Specialized.StringCollection

<Bindable(True), Category("Misc"), Browsable(True), Description("A
collection of Choices to display.")> _
Public Property Choices() As Collections.Specialized.StringCollection
Get
Return m_Choices
End Get
Set(ByVal Value As Collections.Specialized.StringCollection)
m_Choices = Value
End Set
End Property

Do I need to create a new class and inherit from
Collections.Specialized.StringCollection and add a special constructor?
It's complaining about a constructor on String, not on
Collections.Specialized.StringCollection.
 
N

nobody

Ok, I solved the problem. I'm using WebControls.ListItemCollection now
instead of StringCollection. Works like a champ.

nobody said:
In the property window, when I click on the ellipse for my StringCollection
property, I get the window that lets you add and edit items in the
collection. But when I click on the "Add" button, I get "Constructor on
System.String not found."

Here's what I have in my class:
Private m_Choices As New Collections.Specialized.StringCollection

<Bindable(True), Category("Misc"), Browsable(True), Description("A
collection of Choices to display.")> _
Public Property Choices() As Collections.Specialized.StringCollection
Get
Return m_Choices
End Get
Set(ByVal Value As Collections.Specialized.StringCollection)
m_Choices = Value
End Set
End Property

Do I need to create a new class and inherit from
Collections.Specialized.StringCollection and add a special constructor?
It's complaining about a constructor on String, not on
Collections.Specialized.StringCollection.

Natty Gur said:
Yes it all about Ilist. you can use StringCollection whuch support iList
and lomites to string elements.


[Bindable(true),
Category("natty"),
DefaultValue(""),
public System.Collections.Specialized.StringCollection Texts
{
get
{
return texts;
}

set
{
texts = value;
}
}

Natty Gur[MVP]

blog : http://weblogs.asp.net/ngur
Mobile: +972-(0)58-888377
 
N

nobody

Ugh! Not so "resolved"! When I run it, it generates
<cc2:QuestionBox id="QuestionBox3" runat="server" Width="576px"
QuestionText="This is my question" Choices="(Collection)"></cc2:QuestionBox>
What's up with the Choices="(Collection)"? What do I have to do to make the
ListItemCollection generate a proper representation? I'm assumming that the
Choices.ToString() is returning "(Collection)".

nobody said:
Ok, I solved the problem. I'm using WebControls.ListItemCollection now
instead of StringCollection. Works like a champ.

nobody said:
In the property window, when I click on the ellipse for my StringCollection
property, I get the window that lets you add and edit items in the
collection. But when I click on the "Add" button, I get "Constructor on
System.String not found."

Here's what I have in my class:
Private m_Choices As New Collections.Specialized.StringCollection

<Bindable(True), Category("Misc"), Browsable(True), Description("A
collection of Choices to display.")> _
Public Property Choices() As Collections.Specialized.StringCollection
Get
Return m_Choices
End Get
Set(ByVal Value As Collections.Specialized.StringCollection)
m_Choices = Value
End Set
End Property

Do I need to create a new class and inherit from
Collections.Specialized.StringCollection and add a special constructor?
It's complaining about a constructor on String, not on
Collections.Specialized.StringCollection.

Natty Gur said:
Yes it all about Ilist. you can use StringCollection whuch support iList
and lomites to string elements.


[Bindable(true),
Category("natty"),
DefaultValue(""),
public System.Collections.Specialized.StringCollection Texts
{
get
{
return texts;
}

set
{
texts = value;
}
}

Natty Gur[MVP]

blog : http://weblogs.asp.net/ngur
Mobile: +972-(0)58-888377
 

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

Top