473,569 Members | 2,611 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.UserContr ol
{
....
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
[DesignerSeriali zationVisibilit y(DesignerSeria lizationVisibil ity.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 5106
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<MyIt emmyItems = new
Collection<MyIt em>();
public Collection<MyIt emItems {get {return myItems;}}

Marc
Apr 23 '07 #2
On 23 Kwi, 12:32, "Marc Gravell" <marc.grav...@g mail.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<MyIt emmyItems = new
Collection<MyIt em>();
public Collection<MyIt emItems {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 MyItemCollectio n myItems;
public MyItemCollectio n 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 MyItemCollectio n (you
may need to make the default (untyped) indexer explicit on the
interface if you are inheriting).

Alternatively you can subclass CollectionEdito r and override a few
things (perhaps CollectionItemT ype, but I can't remember off-hand)

Marc
Apr 23 '07 #4
On 23 Kwi, 14:13, "Marc Gravell" <marc.grav...@g mail.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 MyItemCollectio n (you
may need to make the default (untyped) indexer explicit on the
interface if you are inheriting).

Alternatively you can subclass CollectionEdito r and override a few
things (perhaps CollectionItemT ype, but I can't remember off-hand)

Marc
I added typed indexer but the problem still exists. I will try to
subclass CollectionEdito r.
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.Collecti ons;

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.SelectedObje ct = new MyOuterItem();
Application.Run (f);
}
}
}
public class MyOuterItem {
private readonly MyDataCollectio n items = new MyDataCollectio n();
public MyDataCollectio n 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 MyDataCollectio n : CollectionBase {
public MyDataItem this[int index] {
get { return (MyDataItem)Lis t[index]; }
set { List[index] = (MyDataItem)val ue; }
}
}
Apr 24 '07 #6
On 24 Kwi, 13:04, "Marc Gravell" <marc.grav...@g mail.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 MyDataCollectio n. Designer is using this converter
by calling method ConvertTo but it never calls ConvertFrom. I also set
[DesignerSeriali zationVisibilit y(DesignerSeria lizationVisibil ity.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...@g mail.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
2722
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. The problem is the article is in VisualBasic. I already get the collection to be recognized as a Data Source by the IDE. It populated the DataGrid...
2
3163
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 problems that I have encountered to date and the solutions (if any) that I found....
3
4307
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 button throws an error "Constructor on type System.String not found.". I may understand this message - there are too many contractor and non of them...
16
2573
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 VB.NET class that exposes those objects to COM perfectly. However I ran into a problem because some of these objects requires a Collection. When I...
4
2498
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 Inherits System.Windows.Forms.UserControl Private _Collection As GridTableStylesCollection
1
1952
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 the collection from the toolbar to the form editor. Now the problem is when I add a new property to the Person class, wich type is another...
0
2496
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 don't work nearly as well as they should, even for analysts and power users. The reason they haven't reached the masses is because most of the tools...
4
2692
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 exposed properties of the constituent controls (e.g., they control how many constitutent controls are displayed). I am at a loss as to how to go...
2
1961
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 looks something like this: Tibco-->Transports-->Transport Where Tibco is the overall component that owns a collection of Transports and each...
0
7700
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7924
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
8125
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7676
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
6284
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5513
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
3653
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
1
2114
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
0
938
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.