I've noticed the SqlDataAdapterDesigner adds the verbs "Generate DataSet..."
and "Preview data..." to the ROOT component designer (e.g. if the
SqlDataAdapter is placed on a Form, the Form gets the verbs too).
I actually need to do this for a Component that is a child of a Component
(in the Component Designer), not a Form. So I have been able to add the
verbs to the Parent (Root) Component fromt the child component's Designer's
Initialize method, like this:
public class AdaptersMapperDesigner : ComponentDesigner
{
...
public override void Initialize(IComponent component)
{
base.Initialize(component);
AddRootVerbs();
}
private void AddRootVerbs()
{
Component root =
(Component)GetRootComponent(this.AdaptersMapper);
IDesigner rootDesigner = GetComponentDesigner(root);
if (rootDesigner != null)
{
rootDesigner.Verbs.Add(
new DesignerVerb("Add Adapter...", new
EventHandler(AddSqlDataAdapterHandler)));
}
}
public IDesigner GetComponentDesigner(IComponent comp)
{
IDesignerHost host = GetDesignerHost(comp);
if (host != null)
{
return host.GetDesigner(comp);
}
return null;
}
public IDesignerHost GetDesignerHost(IComponent comp)
{
if (comp.Site != null)
{
return
(IDesignerHost)comp.Site.GetService(typeof(IDesignerHost));
}
return null;
}
public DesignerVerbCollection GetComponentVerbs(IComponent
comp)
{
IDesigner designer = GetComponentDesigner(comp);
if (designer != null)
{
return designer.Verbs;
}
return new DesignerVerbCollection();
}
public IComponent GetRootComponent(IComponent comp)
{
IDesignerHost host = GetDesignerHost(comp);
if (host != null)
{
return host.RootComponent;
}
return null;
}
...
}
However this doesn't add the verbs when the Component design surface is
just opened (as the SqlAdapterDesigner does), even though the Initialize
method is being called: I need to click any child component and then click
the design surface again to deselect it, only then the new verb appears in
the root Component's properties.
So my question is: what's the proper procedure to add these verbs to the
root component, how does the SqlAdapterDesigner do it?
Juan Ignacio Gelos - 16 Nov 2005 21:42 GMT
The answer to this question, by Tim Dawson, can be found at the Divelements
website:
http://community.divelements.co.uk/CS/forums/10558/ShowPost.aspx
BTW, I strongly recommend their components, and as can be seen, their
support is excellent.
Regards,
Juan