Click here to Skip to main content
15,890,043 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:

Dragged a custom control into a form , I want to give a property of the custom control load multiple values, how can I do?Dragged into a form in a custom control before or after what the property would trigger?

code like this:

public partial class MyControl : System.Windows.Forms.TextBox
{
public MyControl()
{
InitializeComponent();
}

private ShowFields _showFields = new ShowFields();
[DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
[Editor(typeof(ShowField_CollectionEditor), typeof(System.Drawing.Design.UITypeEditor))]
public ShowFields ShowFields
{
get
{
//I want to add two ShowField like this, when this custom control is dragged into a Form in the first time.
//But always add the two ShowField ,when the form is opened.
//if (_showFields == null)
//{
// _showFields = new ShowFields();
// _showFields.AddRange(new ShowField[] { new ShowField("OurCode", "Code"), new ShowField("OurName", "Name") });
//}

return _showFields;
}
}
}

public class ShowField
{
private string _colName;

[Category("ShowItem")]
[DefaultValue(typeof(string), "")]
[DesignerSerializationVisibility(DesignerSerializationVisibility.Visible)]
public string ColName
{
get { return _colName; }
set
{
_colName = value;
}
}

private string _showName;
[Category("ShowItem")]
[DefaultValue(typeof(string), "")]
[DesignerSerializationVisibility(DesignerSerializationVisibility.Visible)]
public string ShowName
{
get { return _showName; }
set { _showName = value; }
}

public ShowField(string colName, string showName)
{
_colName = colName;
_showName = showName;
}

public ShowField()
{
}

}

public class ShowFields : System.Collections.CollectionBase
{
public ShowFields()
{

}

public ShowField Add(ShowField si)
{
this.InnerList.Add(si);
return si;
}

public void Remove(ShowField si)
{
this.InnerList.Remove(si);
}

public bool Contains(ShowField si)
{
return this.InnerList.Contains(si);
}

public ShowField this[int i]
{
get { return (ShowField)this.InnerList[i]; }
set
{
this.InnerList[i] = value;
}
}

public void AddRange(ShowField[] si)
{
this.InnerList.AddRange(si);
}

public ShowField[] GetValues()
{
ShowField[] si = new ShowField[this.InnerList.Count];
this.InnerList.CopyTo(0, si, 0, this.InnerList.Count);
return si;
}
}

public class ShowField_CollectionEditor : System.ComponentModel.Design.CollectionEditor
{
private Type[] types;

public ShowField_CollectionEditor(Type type)
: base(type)
{
types = new Type[] { typeof(ShowField) };

}

protected override Type[] CreateNewItemTypes()
{
return types;
}
}

Posted
Updated 17-Nov-09 16:58pm
v2

1 solution

What do you mean when you say "I want to give a property of the custom control load multiple values" ?

Are you saying you want to set a property of the custom control?

Please provide more details, including code sample to show us what the custom control does.

 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900