Windows Develop Bookmark and Share   
 index > Windows Forms General > PropertyGrid does not show controlName at Runtime ?
 

PropertyGrid does not show controlName at Runtime ?

Hi,

Can some one tell me how to get the Windows PropertyGrid to display the name of my control at runtime? for some reason i see all the other properties except the Name?, i have looked at the propertygrid once i have assigned it to my control and the Name of thecontrol is not there, can someone tell my why this is? but at design time if you assign the PropertyGrid to the control you want its property displayed in the Property grid, (that is atdesign time, Clicking on the PropertyGrid so that you can see its properties in visual studio's properties window, [Hence the Properties of the PropertyGrid Control], and assigning the SelectedObject property to the Control eg a textbox) you see the under the design category of the PropertyGrid the Name of the Control is there! , but at run time this Design category does not exist, obviously because you are now at runtime....so my issue is how do you get the name property of you control to show up in the PropertyGrid like the other properties of that conrol ?

phew! thanks

...oh and by the way i do know you can create a class and add properties to that class and decorate those properties with all kinds of attributes you want to show up in the PropertyGrid ,and then get your control to inherit from that class before assigning it to the PropertyGrid to display the controls properties.

but surely there must be an easier way without going throught creating a new class and then getting your e.g textbox control to inherit it before assigning it to your PropertyGrid? this is good if you want to customise your propertyGrid categories and properties for your control....but what is you just want to use the Property grid as is "out of the Box" and you want the name of your control to be shown at runtime so that you can just change the name of the control ?

ShadowOfTheBeast  Saturday, November 24, 2007 10:14 PM
The extender provider is not your solution but the mechanism that publishes the Name property at designtime. You can't use it at runtime. If you don't want to derive from the parent control and simply override the Name property (which would call the base property), you can create your own TypeConverter, grab the parent properties, add the base Name property and eliminate some that you don't want.

Best regards,


Nicolas Cadilhac @ VisualHint
Smart PropertyGrid.Net
Microsoft PropertyGrid Resource List
Free PropertyGrid for MFC
Smart FieldPackEditor.Net / DateTimePicker

VisualHint  Tuesday, November 27, 2007 5:57 PM

Is this question specific to VS? Or related to Windows Workflow Foundation, e.g.the re-hosted workflow designer or a sample like Workflow Manager or Monitor?

Tom Lake  Monday, November 26, 2007 6:49 AM

This question is specific to VS.Net (winforms)2.0.thanks

ShadowOfTheBeast  Monday, November 26, 2007 1:15 PM
Hi,

I know exactly what happens because a customer had this issue some days ago.

You will se the Name property at design time because there is an extender provider (NameExtenderProvider) that publishes this property. Of course, at runtime it won't and moreover the Control.Name property is not browsable (the attribute is set to false in the Control class). You can use the usual techniques to set it to browsable (derive from the control and override the Name property, publish the properties with a new TypeConverter or publish the properties with a new Type descriptor. More abruptly you could change the Browsable. In SPG this is simplier because you can override the filtering process and include a property that would normally be non browsable).

Best regards,


Nicolas Cadilhac @ VisualHint
Smart PropertyGrid.Net
Microsoft PropertyGrid Resource List
Free PropertyGrid for MFC
Smart FieldPackEditor.Net / DateTimePicker


VisualHint  Tuesday, November 27, 2007 3:20 PM

Hi Nicolas,

thanks so much for answering my question, Now i do know of the technique whereby you create a class with all the properties you want and decorate them with the usual attributes e.g :

<CategoryAttribute("Application"), _
Browsable(True), _
[ReadOnly](False), _
BindableAttribute(False), _
DefaultValueAttribute(""), _
DesignOnly(False), _
DescriptionAttribute("Enter Title for the application")> _

Public String Title

{
get

{
Return _Title

}
Set

{

_Title = Value

}

}

but how do i use the NameExtenderProvider ? i dont know of this technique could you please ellaborate possibly with a code sample?

as i am trying to display the Name without having to create a new Name property for my usercontrol to return the windows default control's name, also i am trying to hide some of the sections that the PropertyGrid Control Provides as my usercontrols do not need to display absolutely every property you can imagine of the current control, i amsure this is the default of course, but there must be a way of displaying the sections you want, and setting of the properties displayed to read only e.tc ?

thanks very much

ShadowOfTheBeast  Tuesday, November 27, 2007 5:26 PM
The extender provider is not your solution but the mechanism that publishes the Name property at designtime. You can't use it at runtime. If you don't want to derive from the parent control and simply override the Name property (which would call the base property), you can create your own TypeConverter, grab the parent properties, add the base Name property and eliminate some that you don't want.

Best regards,


Nicolas Cadilhac @ VisualHint
Smart PropertyGrid.Net
Microsoft PropertyGrid Resource List
Free PropertyGrid for MFC
Smart FieldPackEditor.Net / DateTimePicker

VisualHint  Tuesday, November 27, 2007 5:57 PM

You can use google to search for other answers

Custom Search

More Threads

• The wheel...rediscovered (Custom Scrollbars)
• Windows Form vs Dialog Box
• Class Event triggering a method on a Form...
• Hatch method in Framwork 3.5 with visualstudio 2008
• "System.OutOfMemoryException" When adding a WebBrowser control to my application
• Preventing User from entering Text into a TextBox Control
• Print a MS Word document
• PropertyGrid - Changing a cell's forecolor at runtime
• Customizing ToolTip Appearance
• printing barcodes