This is a migrated thread and some comments may be shown as answers.

Cannot cancel property generating event

2 Answers 45 Views
PropertyGrid
This is a migrated thread and some comments may be shown as answers.
Louis
Top achievements
Rank 1
Louis asked on 19 Jul 2011, 02:32 AM
Are we supposed to be able to cancel the creation of an item in the RadPropertyGrid by setting the event args Cancel to true?  If so, it's not working for me.  Despite me setting Cancel here, the active property still shows up.

void mainPropertyGrid2_AutoGeneratingPropertyDefinition(object sender, Telerik.Windows.Controls.Data.PropertyGrid.AutoGeneratingPropertyDefinitionEventArgs e)
{
    string propertyName = e.PropertyDefinition.Binding.Path.Path;
    if (!string.IsNullOrWhiteSpace(propertyName))
    {
        var o = ((RadPropertyGrid)sender).Item.GetType().GetProperty(propertyName).GetCustomAttributes(false);
        foreach (object customAttrib in o)
        {
            if (customAttrib is WidgetPropertyAttribute)
            {
 
            }
            else
            {
                e.Cancel = true;
            }
        }
    }
}

2 Answers, 1 is accepted

Sort by
0
Accepted
Maya
Telerik team
answered on 19 Jul 2011, 07:38 AM
Hi Louis,

I have tested the scenario described, but still I was not able to reproduce it. May you take a look at the sample attached to verify whether I am missing something or if there is any misunderstandings according to your requirements ? 

All the best,
Maya
the Telerik team

Register for the Q2 2011 What's New Webinar Week. Mark your calendar for the week starting July 18th and book your seat for a walk through of all the exciting stuff we will ship with the new release!

0
Louis
Top achievements
Rank 1
answered on 19 Jul 2011, 08:13 PM
Thanks for the example.  After a little more investigation I found out that GetCustomAttributes wasn't including our WidgetProperty attribute by default.  I need to specify its type in the call to GetCustomAttributes.  So, this works:
var o = ((RadPropertyGrid)sender).Item.GetType().GetProperty(propertyName).GetCustomAttributes(typeof(WidgetPropertyAttribute), false);
if (o.Length == 0)
{
e.Cancel = true;
}

Thanks again!
Tags
PropertyGrid
Asked by
Louis
Top achievements
Rank 1
Answers by
Maya
Telerik team
Louis
Top achievements
Rank 1
Share this question
or