Cannot cancel property generating event

3 posts, 1 answers
  1. Louis
    Louis avatar
    24 posts
    Member since:
    Oct 2010

    Posted 18 Jul 2011 Link to this post

    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. Answer
    Maya
    Admin
    Maya avatar
    4062 posts

    Posted 19 Jul 2011 Link to this post

    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!

  3. DevCraft banner
  4. Louis
    Louis avatar
    24 posts
    Member since:
    Oct 2010

    Posted 19 Jul 2011 Link to this post

    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!
Back to Top