Windows Develop Bookmark and Share   
 index > Windows Forms Designer > Custom CollectionEditor
 

Custom CollectionEditor

Hi.

I have a test control here that has a list of columns in a strongly typed List. Column class has IComponent interface like this:

Code Snippet

public class Column : IComponent

{

public event EventHandler Disposed;

private string m_title;

private string m_toolTip;

private bool m_active;

private ISite m_fakeSite;

public Column()

{

m_active = false;

m_title = null;

m_toolTip = null;

}

[ Localizable(true) ]

public string Title

{

get { return m_title; }

set { m_title = value; }

}

[ Localizable(true) ]

public string ToolTip

{

get { return m_toolTip; }

set { m_toolTip = value; }

}

public bool Active

{

get { return m_active; }

set { m_active = value; }

}

public void Dispose()

{

if (this.Disposed != null)

this.Disposed(this, EventArgs.Empty);

}

[ Browsable(false) ]

public ISite Site

{

get { return m_fakeSite; }

set { m_fakeSite = value; }

}

}

My control looks like this:

Code Snippet

public class TestButton : Button

{

private string m_poruka;

private List<Column> m_kolekcija = new List<Column>();

[ Localizable(true) ]

public string Message

{

get { return m_poruka; }

set { m_poruka = value; }

}

[DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]

[Editor(typeof(ColumnListEditor), typeof(System.Drawing.Design.UITypeEditor))]

public List<Column> Columns

{

get { return m_kolekcija; }

}

}

And my ColumnListEditor looks like this:

Code Snippet

public class ColumnListEditor : CollectionEditor

{

public ColumnListEditor(Type type)

: base(type)

{

}

protected override string GetDisplayText(object value)

{

Column stup = (Column)value;

return stup.Title;

}

}

This looks simple enough but it doesn't work. If I press Add button in editor the error says: List box contains too many items.

If I change Editor attribute of aColumns propertyto point at CollectionEditor instead of ColumnListEditor that everything works fine except the fact that I'm seeing Column1, Column2... in the editor. I want to change display text in the editor.

Any help is appreciated. Thanks.

Srdjan_Njiric  Thursday, September 11, 2008 11:58 AM

Hi.

I'm bumping this a bit since I haven't found a solution to this one. I don't know why my ColumnListEditor class doesn't work.

I would be grateful for any suggestions.

Srdjan_Njiric  Monday, October 06, 2008 1:04 PM
[DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
[Editor(typeof(CollectionEditor), typeof(System.Drawing.Design.UITypeEditor))]
public List<Column>Columns {
get { return m_kolekcija; }
set {m_kolekcija = value; }
}

I think this will be sucess...
And this is my code...you can refer...

usingSystem;
usingSystem.Collections.Generic;
usingSystem.Text;
usingSystem.Collections;
usingSystem.Windows.Forms;
usingSystem.Drawing;
usingSystem.ComponentModel;
usingSystem.ComponentModel.Design;
usingMylib;
namespaceMyLib
{
publicpartialclass动态?Component
{
public动?)
{
InitializeComponent();
}
public动?IContainercontainer)
{
container.Add(this);
InitializeComponent();
}
privateList<动态类>_数组=newList<动态类>();
[Category("BusinessObjectControl")]
[DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
[Editor(typeof(CollectionEditor),typeof(System.Drawing.Design.UITypeEditor))]
publicList<动态类>数组
{
get{return_数组;}
set{_数组=value;}
}
}
publicclass动态类
{
privateint_数值?0;
publicint数?
{
get{return_数?}
set{_数值?value;}
}
privatestring_文本="";
publicstring文本
{
get{return_文本;}
set{_文本=value;}
}
publicoverridestringToString()
{
return_数?ToString()+"|"+_文本;
}
}
}

You can change variable to enghlish....
  • Proposed As Answer bytssing Tuesday, February 10, 2009 6:00 AM
  •  
tssing  Tuesday, February 10, 2009 5:59 AM

You can use google to search for other answers

Custom Search

More Threads

• Oder of events for textbox
• Visual Studio 2005 Beta 2 Designer futures
• Custom Composite Controls
• C# Listbox control from other forms
• Datagrid or user control
• Can you get to the open project or solution files while in a Designer in Design mode
• DesignTimeVisible error in VB project
• Good Book or Set of Rules for Control Development
• Designer can't find my class?
• Creating Licensed control