Windows Develop Bookmark and Share   
 index > Windows Forms Designer > Problems with the "(Name)" Property when I implements IExtenderListService
 

Problems with the "(Name)" Property when I implements IExtenderListService

Hi, I've implemented a form designerhost using the MSDN sample: DesignerHosting.
I created some new properties using the IExtenderProvider interface andIimplemented theIExtenderListService interface in my DesignerHost.
Thaswas the only way that my new properties were shown in the PropertyGrid for every component i added to the designer. This gone good.
The problem is thatI also implement a "Name" property using the a extenderprovider, and in the propertygrid this property nows appears TWO TIMES. Every time y change the value of this property it changes in the two properties at the same time.

If I quit the implementation of IExtenerListService then all the properties I created disappear in the PropertyGrid, and also the TWO "Name" properties.

I can't resolve this problem, please Help me !!!

This is part of the code in my DesignerHost class that implements the IExtenderListService) :

// Services that we already have implemented on my designerhost object
serviceContainer.AddService(typeof(IExtenderListService), this);

// Configure extender providers.
((IExtenderProviderService)this).AddExtenderProvider(new BLNameExtenderProvider(this));
((IExtenderProviderService)this).AddExtenderProvider(new BLInitFunction(this));

This is the code of my "Name" property extender provider:

using System;
using System.ComponentModel;
using System.ComponentModel.Design;
using System.Diagnostics;
using System.Collections;

[ProvideProperty("Name", typeof(IComponent))]
public class BLNameExtenderProvider : IExtenderProvider {
private static Attribute[] designerNameAttribute = new Attribute[] {new BLDesignerNameAttribute(false)};
private BLDesignerHost host;

internal BLNameExtenderProvider(BLDesignerHost host) {
this.host = host;
}

public BLDesignerHost Host {
get {return host;}
}

[DesignerSerializationVisibility(DesignerSerializationVisibility.Content),
BLDesignerName(true),
Browsable(true),
ReadOnly(false),
ParenthesizePropertyName(true),
MergableProperty(false),
Description("The name property for the component"),
Category("Design")]

public virtual string GetName(IComponent comp) {
ISite site = comp.Site;
if (site != null) {
return site.Name;

}
return null;
}

public void SetName(IComponent comp, string newName) {

newName = newName.Trim();

BLDesignSite cs = (BLDesignSite) comp.Site;

if (newName.Equals(cs.Name)) return;

if (string.Compare(newName, cs.Name, true) != 0) {

Host.CheckName(newName);

}

// Find the name property provided by us.

((IComponentChangeService)Host).OnComponentChanging(comp, TypeDescriptor.GetProperties(comp, designerNameAttribute)["Name"]);

Host.Sites.Remove(cs.Name);

Host.Sites[newName] = cs;

string oldName = cs.Name;

cs.SetName(newName);

Host.OnComponentRename(new ComponentRenameEventArgs(comp, oldName, newName));

((IComponentChangeService)Host).OnComponentChanged(comp, TypeDescriptor.GetProperties(comp, designerNameAttribute)["Name"], oldName, newName);

}

#region IExtenderProvider Members

bool IExtenderProvider.CanExtend(object extendee)

{

return true;

}

#endregion

}


THANKS A LOT !!!!

GABRIEL


Gabriel Vila  Thursday, October 26, 2006 4:41 PM

Maybe your component or usercontrol must to implement a custom ExpandableObjectConverter.

In this custimized class you can 'filter' the properties that you want to show or display in a property grid. Like an idea, you can add an custom attribute to your class to filter only the properties that have this custom attribute.

Regards

Tabas  Thursday, October 26, 2006 5:00 PM

Thanks for your answer !!

I'm now hidding some properties with an implementation of ITypeDescriptorFilterService. I try to do the same with the (Name) property but I can't.

The components i use are the microsoft controls (buttons, textboxes, etc.). I don't have usercontrols.
I've a PropertyGrid to show the selected control properties. The first problem I'd, was that the "Name" property didn't appeared, so I'd to implement the IExtenderListService interface in this way:

#region IExtenderListService Members

public IExtenderProvider[] GetExtenderProviders()
{

if (extenderProviders == null)
{
extenderProviders =
new ArrayList();
}

IExtenderProvider[] e = new IExtenderProvider[extenderProviders.Count];
extenderProviders.CopyTo(e, 0);
return e;
}

#endregion

serviceContainer.AddService(typeof(IExtenderListService), this);

With this simple implementation the "(Name)" property appeared. This would be fine, but the problem was that if I've a TextBox control called "TextBox1" and a TextBox control called "Textbox2",  When I change the name of one of this control and put the same name as the other, the designer didn't thrown any kind of exception.

I'm still don't know why.

So I created a custom property called Name the same as the DesignerHosting sample have. Then the "Name" property appeared 2 times in the PropertyGrid.

If I can make that the "Name" property (that appears automatically when I implements IExtenderListService) validates the text of the names of the controls, it would be greate !!
The other solution is hide the automatic property name, so only my custom property name appears in the propertygrid.

Can you help me with this ?
Thanks a lot.
Gabriel

 

Gabriel Vila  Thursday, October 26, 2006 5:31 PM

Gabriel,

Can you help me?

Ihave the same problem, could you tell me how youresolve this problem, help me please, my e-mail is miguel_lopezr@hotmail.com

thanks,

Miguel

Miguello  Wednesday, November 14, 2007 9:39 PM

You can use google to search for other answers

Custom Search

More Threads

• Form.designer separated from its form file
• Custom checkbox and radiobutton control
• Clearing all text boxes
• PropertyGrid & UITypeEditor
• updating a ListView causes it to flash
• Limiting property selections
• Question on tabcontrol and tabpages in winforms(vb.net).
• Designer for developing report templates
• Snaplines in CustomDesigner
• controls created on the fly