J
Joe
Hello.
I have a component that adds a property to other controls similar to
Tooltip. The property is added in the Properties window as expected.
The Get method return a collection which derives from List<>. When the user
clicks the ... for the property the default editor comes up allowing the
user to Add or Remove items. This seems to work fine.
The issue I get is when I look at the code that was added it is not correct.
Here's what I have:
class MyItem
{
private string str1;
public string Str1
{
get
{
return str1;
}
set
{
str1 = value;
}
}
[TypeConverter(typeof(ExpandableObjectConverter))]
class MyList : List<MyItem>
{
}
[ProvideProperty("MyPropertyList", typeof(Control))]
public partial class MyPropertyListComponent : Component,
IExtenderProvider
{
....
public void SetMyPropertyList(Control control, MyList list)
{
if (control == null)
return;
if (Table.ContainsKey(control))
Table[control] = list;
else
Table.Add(control, list);
}
public MyList GetMyPropertyList(Control control)
{
MyList list = null;
if (Table.ContainsKey(control))
list = Table[control];
else
{
list = new MyList();
Table.Add(control, list);
}
return list;
}
}
Here's is how the designer adds the code:
myItem1 = new MyItem();
.....
//
// label1
//
myItem1.Str1 = "Some value";
new MyList().Add(myItem);
....
What happens is that MyPropertyListComponent never gets the items added to
it. I would expect to see something like
MyPropertyListComponent.SetMyPropertyList(label1, myList);
Does this not work with complete classes? If I use a string instead of
MyList then it works. I get
MyPropertyListComponent.SetMyPropertyList(label1, "some string");
Thanks for any help.
Joe
I have a component that adds a property to other controls similar to
Tooltip. The property is added in the Properties window as expected.
The Get method return a collection which derives from List<>. When the user
clicks the ... for the property the default editor comes up allowing the
user to Add or Remove items. This seems to work fine.
The issue I get is when I look at the code that was added it is not correct.
Here's what I have:
class MyItem
{
private string str1;
public string Str1
{
get
{
return str1;
}
set
{
str1 = value;
}
}
[TypeConverter(typeof(ExpandableObjectConverter))]
class MyList : List<MyItem>
{
}
[ProvideProperty("MyPropertyList", typeof(Control))]
public partial class MyPropertyListComponent : Component,
IExtenderProvider
{
....
public void SetMyPropertyList(Control control, MyList list)
{
if (control == null)
return;
if (Table.ContainsKey(control))
Table[control] = list;
else
Table.Add(control, list);
}
public MyList GetMyPropertyList(Control control)
{
MyList list = null;
if (Table.ContainsKey(control))
list = Table[control];
else
{
list = new MyList();
Table.Add(control, list);
}
return list;
}
}
Here's is how the designer adds the code:
myItem1 = new MyItem();
.....
//
// label1
//
myItem1.Str1 = "Some value";
new MyList().Add(myItem);
....
What happens is that MyPropertyListComponent never gets the items added to
it. I would expect to see something like
MyPropertyListComponent.SetMyPropertyList(label1, myList);
Does this not work with complete classes? If I use a string instead of
MyList then it works. I get
MyPropertyListComponent.SetMyPropertyList(label1, "some string");
Thanks for any help.
Joe