<div>I am using ASP.Net with C# 4.0. I created a custom gridview control that has the following signature</div> <div> </div> <div>
[Designer(typeof(CRMGridviewDesigner))]
[ParseChildren(true, "GridFields")]
public class CRMGridview : CompositeDataBoundControl, IPostBackEventHandler
</div>
<div> </div>
<div>I am using a Designer Class for the IDE. It has the following signature</div>
<div> </div>
<div>
public class CRMGridviewDesigner : ControlDesigner
</div>
<div> </div>
<div>It exposes the Action Lists via a public property as follows:</div>
<div> </div>
<div>
public override DesignerActionListCollection ActionLists
{
get
{
if (_ActionList == null)
{
_ActionList = new DesignerActionListCollection();
_ActionList.Add(new CRMGridviewActionList((CRMGridview)Component, this));
}
return _ActionList;
}
}
</div>
<div> </div>
<div>Below is my Action List class.</div>
<div> </div>
<div>
public class CRMGridviewActionList : DesignerActionList
{
#region Constructor
internal CRMGridviewActionList(CRMGridview Ctrl, CRMGridviewDesigner Designer)
: base(Ctrl)
{
_LinkedControl = Ctrl;
_Designer = Designer;
}
#endregion
#region Private Members
private CRMGridview _LinkedControl;
private CRMGridviewDesigner _Designer;
#endregion
#region Public Properties
//Each property is a smart tag
public string DataSourceID
{
get
{
return _LinkedControl.DataSourceID;
}
set
{
GetPropertyByName("DataSourceID").SetValue(_LinkedControl, value);
}
}
public bool ShowDeleteColumn
{
get { return _LinkedControl.ShowDeleteColumn; }
set { GetPropertyByName("ShowDeleteColumn").SetValue(_LinkedControl, value); }
}
public bool ShowEditColumn
{
get { return _LinkedControl.ShowEditColumn; }
set { GetPropertyByName("ShowEditColumn").SetValue(_LinkedControl, value); }
}
public bool ShowOrderColumn
{
get
{
return _LinkedControl.ShowOrderColumn;
}
set
{
GetPropertyByName("ShowOrderColumn").SetValue(_LinkedControl, value);
}
}
public SelectColumnOptions ShowSelectColumn
{
get
{
return _LinkedControl.ShowSelectColumn;
}
set
{
GetPropertyByName("ShowSelectColumn").SetValue(_LinkedControl, value);
}
}
public bool ShowExpandColumn
{
get
{
return _LinkedControl.ShowExpandColumn;
}
set
{
GetPropertyByName("ShowExpandColumn").SetValue(_LinkedControl, value);
}
}
public string ExpandFieldName
{
get
{
return _LinkedControl.ExpandFieldName;
}
set
{
GetPropertyByName("ExpandFieldName").SetValue(_LinkedControl, value);
}
}
#endregion
#region Private Methods
//A property cannot be set directly because other Visual Studio functions
// have to be aware of its changes. Therefor GetPropertyName is created
private PropertyDescriptor GetPropertyByName(string PropName)
{
PropertyDescriptor Prop;
Prop = TypeDescriptor.GetProperties(_LinkedControl)[PropName];
if (Prop == null)
throw new ArgumentException("Property not found", PropName);
else
return Prop;
}
#endregion
#region Public Methods
//This function adds the smart tags and headers to the smart tag list
public override DesignerActionItemCollection GetSortedActionItems()
{
DesignerActionItemCollection Items = new DesignerActionItemCollection();
//Header
Items.Add(new DesignerActionHeaderItem("Appearance"));
Items.Add(new DesignerActionHeaderItem("Data"));
//Items
Items.Add(new DesignerActionPropertyItem("ShowDeleteColumn", "Show delete column.", "Appearance", "Show delete column"));
Items.Add(new DesignerActionPropertyItem("ShowEditColumn", "Show Edit column.", "Appearance", "Show Edit column"));
Items.Add(new DesignerActionPropertyItem("ShowOrderColumn", "Show Order column.", "Appearance", "Show Order column"));
Items.Add(new DesignerActionPropertyItem("ShowSelectColumn", "Show select column", "Appearance", "Show select column"));
Items.Add(new DesignerActionPropertyItem("ShowExpandColumn", "Show expand column", "Appearance", "Show expand column"));
Items.Add(new DesignerActionPropertyItem("DataSourceID", "DataSourceID", "Data", "Link to the data control"));
Items.Add(new DesignerActionPropertyItem("ExpandFieldName", "Expanded Row Field Name", "Data", "Expanded Row Field Name"));
return Items;
}
#endregion
}
</div> <div></div> <div>The smart tag works, but when I use it to edit my control. I lose all my interior markup. Like
my column data, etc. I know I am missing something but I can't seem to find what.</div> <div> </div> <div>Any help is appreciated.</div>
In my mind,I think you should override the CreateChildControl event by initialize the array and set ChildControlsCreated=True。This won't let you create controls again and again。Sample looks like this below:
[Designer(typeof(CRMGridviewDesigner))]
[ParseChildren(true, "GridFields")]
public class CRMGridview : CompositeDataBoundControl, IPostBackEventHandler
{
private CRMGridviewActionList_ActionList=null;
public override DesignerActionListCollection ActionLists
{
get
{
if (_ActionList == null)
{
_ActionList.Add(new CRMGridviewActionList((CRMGridview)Component, this));
}
return _ActionList;
}
}
……………………
protected override void CreateChildControls()
{
_ActionList = new DesignerActionListCollection();
……
}
TimHays
Member
43 Points
14 Posts
My Smart Tag is erasing my internal Content
Dec 09, 2011 05:33 PM|LINK
[Designer(typeof(CRMGridviewDesigner))] [ParseChildren(true, "GridFields")] public class CRMGridview : CompositeDataBoundControl, IPostBackEventHandler</div> <div> </div> <div>I am using a Designer Class for the IDE. It has the following signature</div> <div> </div> <div> </div> <div> </div> <div>It exposes the Action Lists via a public property as follows:</div> <div> </div> <div>public override DesignerActionListCollection ActionLists { get { if (_ActionList == null) { _ActionList = new DesignerActionListCollection(); _ActionList.Add(new CRMGridviewActionList((CRMGridview)Component, this)); } return _ActionList; } }</div> <div> </div> <div>Below is my Action List class.</div> <div> </div> <div>public class CRMGridviewActionList : DesignerActionList { #region Constructor internal CRMGridviewActionList(CRMGridview Ctrl, CRMGridviewDesigner Designer) : base(Ctrl) { _LinkedControl = Ctrl; _Designer = Designer; } #endregion #region Private Members private CRMGridview _LinkedControl; private CRMGridviewDesigner _Designer; #endregion #region Public Properties //Each property is a smart tag public string DataSourceID { get { return _LinkedControl.DataSourceID; } set { GetPropertyByName("DataSourceID").SetValue(_LinkedControl, value); } } public bool ShowDeleteColumn { get { return _LinkedControl.ShowDeleteColumn; } set { GetPropertyByName("ShowDeleteColumn").SetValue(_LinkedControl, value); } } public bool ShowEditColumn { get { return _LinkedControl.ShowEditColumn; } set { GetPropertyByName("ShowEditColumn").SetValue(_LinkedControl, value); } } public bool ShowOrderColumn { get { return _LinkedControl.ShowOrderColumn; } set { GetPropertyByName("ShowOrderColumn").SetValue(_LinkedControl, value); } } public SelectColumnOptions ShowSelectColumn { get { return _LinkedControl.ShowSelectColumn; } set { GetPropertyByName("ShowSelectColumn").SetValue(_LinkedControl, value); } } public bool ShowExpandColumn { get { return _LinkedControl.ShowExpandColumn; } set { GetPropertyByName("ShowExpandColumn").SetValue(_LinkedControl, value); } } public string ExpandFieldName { get { return _LinkedControl.ExpandFieldName; } set { GetPropertyByName("ExpandFieldName").SetValue(_LinkedControl, value); } } #endregion #region Private Methods //A property cannot be set directly because other Visual Studio functions // have to be aware of its changes. Therefor GetPropertyName is created private PropertyDescriptor GetPropertyByName(string PropName) { PropertyDescriptor Prop; Prop = TypeDescriptor.GetProperties(_LinkedControl)[PropName]; if (Prop == null) throw new ArgumentException("Property not found", PropName); else return Prop; } #endregion #region Public Methods //This function adds the smart tags and headers to the smart tag list public override DesignerActionItemCollection GetSortedActionItems() { DesignerActionItemCollection Items = new DesignerActionItemCollection(); //Header Items.Add(new DesignerActionHeaderItem("Appearance")); Items.Add(new DesignerActionHeaderItem("Data")); //Items Items.Add(new DesignerActionPropertyItem("ShowDeleteColumn", "Show delete column.", "Appearance", "Show delete column")); Items.Add(new DesignerActionPropertyItem("ShowEditColumn", "Show Edit column.", "Appearance", "Show Edit column")); Items.Add(new DesignerActionPropertyItem("ShowOrderColumn", "Show Order column.", "Appearance", "Show Order column")); Items.Add(new DesignerActionPropertyItem("ShowSelectColumn", "Show select column", "Appearance", "Show select column")); Items.Add(new DesignerActionPropertyItem("ShowExpandColumn", "Show expand column", "Appearance", "Show expand column")); Items.Add(new DesignerActionPropertyItem("DataSourceID", "DataSourceID", "Data", "Link to the data control")); Items.Add(new DesignerActionPropertyItem("ExpandFieldName", "Expanded Row Field Name", "Data", "Expanded Row Field Name")); return Items; } #endregion }</div> <div></div> <div>The smart tag works, but when I use it to edit my control. I lose all my interior markup. Like my column data, etc. I know I am missing something but I can't seem to find what.</div> <div> </div> <div>Any help is appreciated.</div>Decker Dong ...
All-Star
118619 Points
18779 Posts
Re: My Smart Tag is erasing my internal Content
Dec 11, 2011 02:08 AM|LINK
Hello:)
In my mind,I think you should override the CreateChildControl event by initialize the array and set ChildControlsCreated=True。This won't let you create controls again and again。Sample looks like this below:
[Designer(typeof(CRMGridviewDesigner))]
[ParseChildren(true, "GridFields")]
public class CRMGridview : CompositeDataBoundControl, IPostBackEventHandler
{
private CRMGridviewActionList_ActionList=null;
public override DesignerActionListCollection ActionLists
{
get
{
if (_ActionList == null)
{
_ActionList.Add(new CRMGridviewActionList((CRMGridview)Component, this));
}
return _ActionList;
}
}
……………………
protected override void CreateChildControls()
{
_ActionList = new DesignerActionListCollection();
……
}
}
TimHays
Member
43 Points
14 Posts
Re: My Smart Tag is erasing my internal Content
Dec 12, 2011 11:39 AM|LINK
Thanks for the response.
I don't see in your code where you are setting "ChildControlsCreated=True".
Decker Dong ...
All-Star
118619 Points
18779 Posts
Re: My Smart Tag is erasing my internal Content
Dec 13, 2011 12:22 AM|LINK
In the "protected override void CreateChildControls()"——this event。
Best reguards!