473,396 Members | 1,938 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Collection property & Design Time support

Hello,

I am trying to create a user control which allows the user to enter a
collection of items at design-time. Code example:

public class MyControl : System.Windows.Forms.UserControl
{
....
MyItem [] itemList;

public MyItem [] ItemList
{
get { return itemList; }
set { itemList = value; }
}
....
}

public class MyItem
{
private string caption;

public string Caption
{
get { return caption; }
set { caption = value; }
}
}

I want to add design-time support for ItemList property. Currently in
design mode Visual Studio opens Collection Editor for ItemList
property
and I can define all items but after clicking OK items are not saved
(they just disappear). I tried to use
[DesignerSerializationVisibility(DesignerSerializat ionVisibility.Content)]
for ItemList property but it doesn't help. I also have implemented a
TypeConverter for ItemList which can make a convertion between
collection of items and string - but is also doesn't help. Maybe you
can
help me.

Regards,
Tomasz Siwarga

Apr 23 '07 #1
8 5098
Try changing to a list/collection type rather than an array (it should
be read only). In 2.0 you could probably use

private readonly Collection<MyItemmyItems = new
Collection<MyItem>();
public Collection<MyItemItems {get {return myItems;}}

Marc
Apr 23 '07 #2
On 23 Kwi, 12:32, "Marc Gravell" <marc.grav...@gmail.comwrote:
Try changing to a list/collection type rather than an array (it should
be read only). In 2.0 you could probably use

private readonly Collection<MyItemmyItems = new
Collection<MyItem>();
public Collection<MyItemItems {get {return myItems;}}

Marc

The project is created using .NET 1.1 and I have no chance to change
it to 2.0.
I tried to use collection derived from ArrayList and the problem still
remains.

my code looks like this:
private readonly MyItemCollection myItems;
public MyItemCollection Items { get {return myItems;} }

Maybe you know any working example for .NET 1.1 ...

Thanks for your help,
Regards,
Tom

Apr 23 '07 #3
http://msdn2.microsoft.com/en-us/lib...ioneditor.aspx
This editor can edit collections that have an Item property
Try adding a (typed) Item[int index] indexer to MyItemCollection (you
may need to make the default (untyped) indexer explicit on the
interface if you are inheriting).

Alternatively you can subclass CollectionEditor and override a few
things (perhaps CollectionItemType, but I can't remember off-hand)

Marc
Apr 23 '07 #4
On 23 Kwi, 14:13, "Marc Gravell" <marc.grav...@gmail.comwrote:
http://msdn2.microsoft.com/en-us/lib...ntmodel.design...
This editor can edit collections that have an Itemproperty

Try adding a (typed) Item[int index] indexer to MyItemCollection (you
may need to make the default (untyped) indexer explicit on the
interface if you are inheriting).

Alternatively you can subclass CollectionEditor and override a few
things (perhaps CollectionItemType, but I can't remember off-hand)

Marc
I added typed indexer but the problem still exists. I will try to
subclass CollectionEditor.
Thanks for suggestions,
Tom

Apr 24 '07 #5
I don't have my 1.1 tools "on hand" (and can't be bothered to csc),
but the following might work:

using System;
using System.Windows.Forms;
using System.Collections;

static class Program {
static void Main() {
using (Form f = new Form())
using (PropertyGrid pg = new PropertyGrid()) {
pg.Dock = DockStyle.Fill;
f.Controls.Add(pg);
pg.SelectedObject = new MyOuterItem();
Application.Run(f);
}
}
}
public class MyOuterItem {
private readonly MyDataCollection items = new MyDataCollection();
public MyDataCollection Items { get { return items; } }
}
public class MyDataItem {
public override string ToString() {
return Name;
}
private string name;
public string Name {
get { return name; }
set { name = value; }
}
private int id;
public int Id {
get { return id; }
set { id = value; }
}
}
public class MyDataCollection : CollectionBase {
public MyDataItem this[int index] {
get { return (MyDataItem)List[index]; }
set { List[index] = (MyDataItem)value; }
}
}
Apr 24 '07 #6
On 24 Kwi, 13:04, "Marc Gravell" <marc.grav...@gmail.comwrote:
I don't have my 1.1 tools "on hand" (and can't be bothered to csc),
but the following might work:
.......
Marc,
Your example works fine. I get the same functionality in my code when
I changed ArrayList to CollectionBase. But one more problem still
exists - serialization. After I define collection of items using
property grid in design mode - it should be saved in .resx file or
in .cs file so that I can use it in runtime (just like any other
property of my user control). As I mentioned before I implemented
TypeConverter for MyDataCollection. Designer is using this converter
by calling method ConvertTo but it never calls ConvertFrom. I also set
[DesignerSerializationVisibility(DesignerSerializat ionVisibility.Content)].
But collection of items which now - thanks to your help - can be
defined in desing time using propery grid is never serialized.
Mabye this is also a piece of cake for you :)
Regards,

Tom

Apr 25 '07 #7
The serialization I'm not sure about; however, from what I can see it
must be a: marked serializable, and to use TypeConverter the converter
must also return true from CanConvertFrom and CanConvertTo (for
string).

Marc
Apr 25 '07 #8
On 25 Kwi, 12:29, "Marc Gravell" <marc.grav...@gmail.comwrote:
The serialization I'm not sure about; however, from what I can see it
must be a: marked serializable, and to use TypeConverter the converter
must also return true from CanConvertFrom and CanConvertTo (for
string).

Marc
Marc,

I joined all your suggestions all togother and now I have exactly what
I wanted to have. Thank you for your help.
Best regards,

Tom

Apr 26 '07 #9

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: SammyBar | last post by:
Hi, I'm trying to bind a custom collection class to a data grid, following the guidelines from the article http://msdn.microsoft.com/msdnmag/issues/05/08/CollectionsandDataBinding/default.aspx....
2
by: Brian | last post by:
NOTE ALSO POSTED IN microsoft.public.dotnet.framework.aspnet.buildingcontrols I have solved most of my Server Control Collection property issues. I wrote an HTML page that describes all of the...
3
by: Shimon Sim | last post by:
I have control. One of the properties is implemented as StringCollection. I didn't use any Editor attribute for it. During Design time system shows dialog similar to Items in DropDownList but Add...
16
by: Ben Hannon | last post by:
Hi, I'm writting a COM Class in VB.NET to be used in a VB6 project (Tired of the VB6 hassles with cloning and serializing an object). All my classes I need cloneable/serializable are now in a...
4
by: Michael | last post by:
Dear all .. If I want to use develop a user control and declare a public property which the type is System.Windows.Forms.GridTableStylesCollection For example : Public Class LookAndView...
1
by: Ruben | last post by:
I have a collection (PersonCollection inherits collectionbase and implements ITypedList it's a collection of Person objects) this collection also implements the IComponent interface, so I can drag...
0
by: YellowFin Announcements | last post by:
Introduction Usability and relevance have been identified as the major factors preventing mass adoption of Business Intelligence applications. What we have today are traditional BI tools that...
4
by: Mark Olbert | last post by:
I've written a composite custom control which I would like to have update its design-time display when one of several properties changes at design time. These custom properties are not simply the...
2
by: meyousikmann | last post by:
This will be difficult to explain so bear with me. If anyone is familiar with Tibco Rendezvous and/or Microsoft Messaging, this may make more sense. I've created a hierarchy of objects that...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.