I created a sample UserControl that exposes a Collection
Serialization works in this sample, the single problem I found is that I
want to have an edit updated with number of items in the collection. For
that I had to call Control.Refresh() when CollectionEditor.SetItems() is
called. Can you please use this sample and tell if it is close to what you
need?
Tip1: I have to restart VStudio 2005 quite often (almost each time I modify
control)
Tip 2: I use dbmon or DbgView (from
www.sysinternals.com) to see the output
of System.Diagonostics.Trace.WriteLine even if is in VStudio Designer
Here follows the source code
TestUserControl.cs
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Text;
using System.Windows.Forms;
using System.Collections.ObjectModel;
using System.Drawing.Design;
using System.ComponentModel.Design;
namespace TestCollectionProperty
{
public class TestData
{
int intValue;
String strValue = string.Empty;
public int IntValue
{
get { return intValue; }
set { intValue = value; }
}
public String StrValue
{
get { return strValue; }
set { strValue = value; }
}
}
public class ValuesEditor : CollectionEditor
{
public ValuesEditor()
: base(typeof(List<TestData>))
{ }
protected override object SetItems(object editValue, object[] value)
{
System.Diagnostics.Trace.WriteLine("SetItems1");
System.Diagnostics.Trace.WriteLine("SetItems2: " + editValue);
object retValue = base.SetItems(editValue, value);
Control control = this.Context.Instance as Control;
System.Diagnostics.Trace.WriteLine("SetItems3: " + control);
if (control != null)
{
control.Refresh();
}
return retValue;
}
}
public partial class TestUserControl : UserControl
{
private List<TestData> values = new List<TestData>();
public TestUserControl()
{
InitializeComponent();
}
[Browsable(true)]
[DesignerSerializationVisibility(DesignerSerializat ionVisibility.Content)]
[RefreshProperties(RefreshProperties.All)]
[Editor(typeof(ValuesEditor), typeof(UITypeEditor))]
public List<TestData> Values
{
get { return values; }
}
protected override void OnPaint(PaintEventArgs e)
{
this.textBox.Text = values.Count.ToString();
base.OnPaint(e);
}
}
}
TestUserCode.Design.cs
namespace TestCollectionProperty
{
partial class TestUserControl
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed;
otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Component Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.textBox = new System.Windows.Forms.TextBox();
this.SuspendLayout();
//
// textBox
//
this.textBox.Location = new System.Drawing.Point(24, 50);
this.textBox.Name = "textBox";
this.textBox.Size = new System.Drawing.Size(100, 20);
this.textBox.TabIndex = 0;
//
// TestUserControl
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.Controls.Add(this.textBox);
this.Name = "TestUserControl";
this.ResumeLayout(false);
this.PerformLayout();
}
#endregion
private System.Windows.Forms.TextBox textBox;
}
}
"alex sparsky" <al**@sparkysystems.com> wrote in message
news:si********************************@4ax.com...
[
Description("Items Collection"),
Category("Items"),
DesignerSerializationVisibility(DesignerSerializat ionVisibility.Content),
Editor(typeof(GItemEditor), typeof(UITypeEditor)),
RefreshProperties(RefreshProperties.All),
Browsable( true )
]
and none of those things are helping. :/
this is the header I've already been using.
On Mon, 19 Dec 2005 21:42:00 +0200, "Bele din Carpati"
<cr*******@mail.dntis.ro> wrote:
see how the Controls property of Control object is marked with
DesignerSerializationVisibility:
[DesignerSerializationVisibility(DesignerSerializat ionVisibility.Content),
System.Windows.Forms.SRDescription("ControlContr olsDescr"),
Browsable(false)]
public System.Windows.Forms.Control.ControlCollection Controls
{
get{....}
set{...}
}
Can you please let me know if this is helped you?
Cristi
"alex sparsky" <al**@sparkysystems.com> wrote in message
news:cq********************************@4ax.com. .. Tried that already and it made no difference. I'm still looking for a
solution to this.
On Mon, 19 Dec 2005 20:00:18 +0200, "Bele din Carpati"
<cr*******@mail.dntis.ro> wrote:
I think you should use RefreshPropertiesAttribute.
[RefreshProperties(RefreshProperties.All)]
FooCollection FooProperties