Is it possible that the propertygrid content is filled with a class that has attributes, like
the winform propertygrid?
for example, I have a class from a winform application with some attributes that are shown
in a winform propertygrid
some attributes are:
[Category("Description")]
or
[CategoryAttribute("Properties"), DefaultValueAttribute(false)]
or
[Category("Description"), Browsable(false)] <- this one will not show up in the propertygrid
I noticed that I see all the properties for the class even the properties I don't want the user to see or fill
David.
4 Answers, 1 is accepted
The attributes stated are not internally supported. However there is an easy way to take control with a few additional lines of code .
Basically what you need to do is to handle the AutoGeneratingPropertyDefinition event of RadPropertyGrid.
Inside the handler you can either cancel the creation of the property definition ( e.Cancel - true) , or set its category by setting the GroupName of the property definition.
In case this sounds complicated , you can just paste me the code of your business object ( the one you need edited in RadPropertyGrid) and I will gather a small sample app for you with your object.
Regards,
Pavel Pavlov
the Telerik team
Thank you for being the most amazing .NET community! Your unfailing support is what helps us charge forward! We'd appreciate your vote for Telerik in this year's DevProConnections Awards. We are competing in mind-blowing 20 categories and every vote counts! VOTE for Telerik NOW >>
Hello Albino Vallino,
RadPropertyGrid sort only the list of property definitions. When there is grouping, the group, which has the property definition that is first in the sorted list, will be displayed first. To override this behavior, you can add alternative sorting criteria by using the OrderIndex property of PropertyDefinition, or DisplayAttribute.Order. If the property definitions are autogenerated, you can use the AutoGeneratePropertyDefinitions event and then set the OrderIndex property of the PropertyDefinition instance passed in the args.

thanks for the fast response, I've tried to handle the AutoGeneratingPropertyDefinition event of the propertygrid but I could not
make it work.
The code below a sample class with some attributes from my class, I would be very happy if you could make a example for me.
class TestPropertyGrid
{
[Category("Maintenance"), DefaultValue("")]
public string Description { get; set; }
[Category("Maintenance")]
public int Id { get; set; }
[Category("Maintenance"), DefaultValue(true)]
public bool IsRequired { get; set; }
[Category("Properties"), DefaultValue(true), Browsable(false)]
public bool IsChangeRequired { get; set; }
[Editor(typeof(IconFiles), typeof(System.Drawing.Design.IconEditor)), CategoryAttribute("Icon"), DefaultValueAttribute(true)]
public string Iconfile { get; set; }
}
public class IconFiles : IconEditor
{
string IconPath = @"C:\Temp";
public IconFiles() { }
protected override void InitializeDialog(OpenFileDialog openFileDialog)
{
openFileDialog.Title = "Icons";
openFileDialog.Multiselect = false;
openFileDialog.InitialDirectory = IconPath;
openFileDialog.Filter = "icons (*.ico)|*.ico|All files (*.*)|*.*";
openFileDialog.RestoreDirectory = true;
}
}
David.

private
void
AutoGeneratingPropertyDefinition(
object
a_sender, Telerik.Windows.Controls.Data.PropertyGrid.AutoGeneratingPropertyDefinitionEventArgs a_e)
{
AttributeCollection attributes = TypeDescriptor.GetProperties(InsertClassTypeHere)[a_e.PropertyDefinition.DisplayName].Attributes;
BrowsableAttribute browsable = attributes[
typeof
(BrowsableAttribute)]
as
BrowsableAttribute;
if
(browsable !=
null
)
{
// If browsable set to false cancel, otherwise display
a_e.Cancel = !browsable.Browsable;
}
DescriptionAttribute description = attributes[
typeof
(DescriptionAttribute)]
as
DescriptionAttribute;
if
(description !=
null
)
{
a_e.PropertyDefinition.Description = description.Description;
}
}
