how do I exclude the control name from being displayed in property grid?

  • Thread starter Thread starter mjheitland
  • Start date Start date
M

mjheitland

Hello,

when I use a property grid to display all properties of a control I
want to exclude the control's name.
(The name of my control shall not be altered)
How do I exlude the name?

Greetings,
Michael Heitland
 
mjheitland said:
when I use a property grid to display all properties of a control I
want to exclude the control's name.
(The name of my control shall not be altered)
How do I exlude the name?

Add a Browsable attribute to the property and pass false in the constructor.
Ex:

[Browsable(false)]
public string Name
{
get {/* */}
set {/* */}
}
 
Hi as an experiment i tried to hide the main form's name for when i
create a new project, but cant find where the name of the form is
specified, where i would add that attribute.

Can someone tell me please,

Thanks,

Gary-
Tom said:
mjheitland said:
when I use a property grid to display all properties of a control I
want to exclude the control's name.
(The name of my control shall not be altered)
How do I exlude the name?

Add a Browsable attribute to the property and pass false in the constructor.
Ex:

[Browsable(false)]
public string Name
{
get {/* */}
set {/* */}
}
 
Michael,

You can't bind directly to the control.

What you need to do is expose a class that implements the
ICustomTypeDescriptor interface. This allows an object to expose the type
information, as opposed from it being read from the object itself.

So, in your implementation, you would expose through the GetProperties
method all the properties on the control, except for the "Name" property.

Then, bind the control to the implementation of ICustomTypeDescriptor.

Hope this helps.
 
I have just realised how poorly structured my previous post was, and
how muddled.

I'll try again.

Having read this thread I was interested. I tried to do something
similar to the original poster, namely hide a property of a control.
The control I choose was the Form itself. My question is how do find
the part of code I need to locate, to add the attribute already
provided in this thread, that will hide the property from the IDE.

Thankyou.

Gary-

Hi as an experiment i tried to hide the main form's name for when i
create a new project, but cant find where the name of the form is
specified, where i would add that attribute.

Can someone tell me please,

Thanks,

Gary-
Tom said:
mjheitland said:
when I use a property grid to display all properties of a control I
want to exclude the control's name.
(The name of my control shall not be altered)
How do I exlude the name?

Add a Browsable attribute to the property and pass false in the constructor.
Ex:

[Browsable(false)]
public string Name
{
get {/* */}
set {/* */}
}
 
Tom said:
Add a Browsable attribute to the property and pass false in the
constructor. Ex:

[Browsable(false)]
public string Name
{
get {/* */}
set {/* */}
}

I'll have to add to this. As the Name property comes from the Control base
class, you can't change its attributes. You'll need to either write your
own custom control with a different base class, possible Component requiring
a lot more code to write, or as Nicholas points out, write your own
implementation of ICustomTypeDescriptor.

Sorry for the confusion. The Browsable attribute would work for any
properties that you could override or for your own custom properties.
 
I think this is a good juncture to point out that the behaviour of
ICustomTypeDescriptor changed in V2.

Nicholas' answer is correct but there is supplementary info that may also
be interesting to you.

Implementing ICustomTypeDescriptor on a class has no effect when that class
is used in databinding scanarios. We need to implement a full
TypeDescriptionProvider for this.


--
Bob Powell [MVP]
Visual C#, System.Drawing

Ramuseco Limited .NET consulting
http://www.ramuseco.com

Find great Windows Forms articles in Windows Forms Tips and Tricks
http://www.bobpowell.net/tipstricks.htm

Answer those GDI+ questions with the GDI+ FAQ
http://www.bobpowell.net/faqmain.htm

All new articles provide code in C# and VB.NET.
Subscribe to the RSS feeds provided and never miss a new article.
 
Demetri,

He could, but "new" is pretty much evil, and in this case, it obfuscates
the meaning of the original class.

--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

Demetri said:
He couldn't just create a class that inherits from form and create a
property
with the "new" modifier and the property name as "Name" and add the
Browsable(false) attribute?

--
-Demetri


Nicholas Paldino said:
Michael,

You can't bind directly to the control.

What you need to do is expose a class that implements the
ICustomTypeDescriptor interface. This allows an object to expose the
type
information, as opposed from it being read from the object itself.

So, in your implementation, you would expose through the
GetProperties
method all the properties on the control, except for the "Name" property.

Then, bind the control to the implementation of
ICustomTypeDescriptor.

Hope this helps.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)


mjheitland said:
Hello,

when I use a property grid to display all properties of a control I
want to exclude the control's name.
(The name of my control shall not be altered)
How do I exlude the name?

Greetings,
Michael Heitland
 
Demetri said:
He couldn't just create a class that inherits from form and create a
property
with the "new" modifier and the property name as "Name" and add the
Browsable(false) attribute?


Try it, it won't work. Name is still browsable.
 
Background to my question: I am using a 3rd party designer and don't
want to allow the user to change the name of the controls.

Best solution would be not to show the control name in the property
grid (I like to show it only in the title bar of the property grid).

If it is not possible (or has too much drawbacks) to exclude the name
(all other properties shall be appear in the grid): can I set the value
field of the property grid for 'name' to readonly?

Thanks for being so busy answering me!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top