Browsable Property not working as expected

10 posts, 0 answers
  1. Dharmavaram
    Dharmavaram avatar
    72 posts
    Member since:
    Jun 2013

    Posted 19 Sep Link to this post

    Hi,

       I have created a class Employee with Properties FirstName,LastName,Title, and Date of Birth. By default  I kept Browsable attribute value 'false' for FirstName Property. In the set block of Title and Date of birth I am trying to change the value of Browsable attribute value of firstName Property to true and false respectively. 

         It is changing the value to true and showing the FirstName Property while loading the grid.After that again if I edit DataOfBirth it is not hiding the property 'FirstName' even when i set browsable attribute value false.

     

    I am using following code to modify the browsable attribute value:

       public void ModifyBrowsableAttributeOfProperty(string prop, bool value)
            {
                PropertyDescriptor descriptor = TypeDescriptor.GetProperties(this.GetType())[prop];

                BrowsableAttribute attribute = (BrowsableAttribute)descriptor.Attributes[typeof(BrowsableAttribute)];


                FieldInfo field_info = attribute.GetType().GetField("Browsable", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Public | System.Reflection.BindingFlags.Static | System.Reflection.BindingFlags.IgnoreCase);

                if ((Convert.ToBoolean(field_info.GetValue(attribute)) != value))
                {
                    field_info.SetValue(attribute, value);
                }

            }

     

    In simple words it is working only when we change while loading rest of the times when we change browsable Property value it is not refelecting in propertygrid.

     

    Regards,

    Nagasree.

         

     

  2. Dilyan Traykov
    Admin
    Dilyan Traykov avatar
    368 posts

    Posted 19 Sep Link to this post

    Hello Nagasree,

    In order to notify RadPropertyGrid about the change in the property's Browsable attribute, you will need to call the new ReloadData method which will refresh RadPropertyGrid's data engine.

    Please let me know whether such an approach would be suitable for your requirements.

    Regards,
    Dilyan Traykov
    Telerik by Progress
    Do you need help with upgrading your AJAX, WPF or WinForms project? Check the Telerik API Analyzer and share your thoughts.
  3. UI for WPF is Visual Studio 2017 Ready
  4. Dharmavaram
    Dharmavaram avatar
    72 posts
    Member since:
    Jun 2013

    Posted 19 Sep in reply to Dilyan Traykov Link to this post

    Hi Dilyan,

         Is it similar to Refresh method available in winforms?? I am using Telerik R2 2016 and I may take sometime to move R3. Is there any alternative to do this?

    Regards,

    Nagasree.

     

  5. Dilyan Traykov
    Admin
    Dilyan Traykov avatar
    368 posts

    Posted 20 Sep Link to this post

    Hello Dharmavaram,

    I'm afraid that there's no alternative to the ReloadData method in previous versions of the controls.

    You could, however, use the Project Upgrade Wizard in order to easily update the version of your controls. Do let me know how this goes.

    Regards,
    Dilyan Traykov
    Telerik by Progress
    Do you need help with upgrading your AJAX, WPF or WinForms project? Check the Telerik API Analyzer and share your thoughts.
  6. Dharmavaram
    Dharmavaram avatar
    72 posts
    Member since:
    Jun 2013

    Posted 26 Sep in reply to Dilyan Traykov Link to this post

    Hi Dilyan,

               I thought of using this method in PropertyValue changed event of PropertyGrid.But this event not available on PropertyGrid.I am using MVVM, and I have to refresh Propertygrid once property got changed.where Can I change it? 

    Regards,

    Nagasree.

  7. Dilyan Traykov
    Admin
    Dilyan Traykov avatar
    368 posts

    Posted 27 Sep Link to this post

    Hello Nagasree,

    May I ask how and when exactly you're changing the Browsable attribute of the property? Please bear in mind that such a change will not raise the PropertyChanged event.

    I'm attaching a sample project where I've used a custom command to change the Browsable attribute's value and also call RadPropertyGrid's ReloadData method. Please have a look at it and let me know whether such an approach would work for you.

    Regards,
    Dilyan Traykov
    Telerik by Progress
    Do you need help with upgrading your AJAX, WPF or WinForms project? Check the Telerik API Analyzer and share your thoughts.
  8. Dharmavaram
    Dharmavaram avatar
    72 posts
    Member since:
    Jun 2013

    Posted 27 Sep Link to this post

    Hi Dilyan,

          I am changing the browsable attribute of one of the property based on the value of another property.For example if I have two properties ShowCriteria and Criteria.I will show criteria property in PropertyGrid only when ShowCriteria value is True.So in the set block of the ShowCriteria I will modify the browsable attribute of Criteria. 

    At that time I have to refresh the Property Grid.If u need further information Please let me know.

     

    Regards,

    Nagasree

  9. Dilyan Traykov
    Admin
    Dilyan Traykov avatar
    368 posts

    Posted 28 Sep Link to this post

    Hello Dharmavaram,

    May I ask if you're using the Browsable property for any other reason than showing/hiding it from RadPropertyGrid. If that is not the case, may I suggest introducing a property inside of your viewmodel which is bound to the object's ShowCriteria property and bind that to the Visibility property of the Criteria's PropertyDefinition?

    I'm attaching a sample project to better demonstrate what I have in mind. Please let me know whether such an approach would work for you.

    Regards,
    Dilyan Traykov
    Telerik by Progress
    Do you need help with upgrading your AJAX, WPF or WinForms project? Check the Telerik API Analyzer and share your thoughts.
  10. Dharmavaram
    Dharmavaram avatar
    72 posts
    Member since:
    Jun 2013

    Posted 28 Sep in reply to Dilyan Traykov Link to this post

    Hi Dilyan,

      It is not feasible solution for me as there are so many properties for which I change Browsable Property based on work flow.I cannot create properties on my view model for every property in modal.

    Any other solution??

  11. Dilyan Traykov
    Admin
    Dilyan Traykov avatar
    368 posts

    Posted 29 Sep Link to this post

    Hello Dharmavaram,

    Another approach would be to handle the PropertyChanged event of your bound item, and call the ReloadData method there, after you've updated the Browsable attribute of the respective property:

    public MainWindow()
    {
        InitializeComponent();
        var club = this.propertyGrid.Item as Club;
        club.PropertyChanged += Club_PropertyChanged;
    }
     
    private void Club_PropertyChanged(object sender, PropertyChangedEventArgs e)
    {
        this.propertyGrid.ReloadData();
    }

    public bool ShowStadiumCapacity
    {
        get { return this.showStadiumCapacity; }
        set
        {
            if (value != this.showStadiumCapacity)
            {
                this.showStadiumCapacity = value;
                this.ModifyBrowsableAttributeOfProperty("StadiumCapacity", this.showStadiumCapacity);
                this.OnPropertyChanged("ShowStadiumCapacity");
            }
        }
    }

    Of course, you can make a check in order to avoid calling the costly ReloadData method each time you modify a property's value.

    Do let me know if you would find such an approach would be suitable.

    Regards,
    Dilyan Traykov
    Telerik by Progress
    Do you need help with upgrading your AJAX, WPF or WinForms project? Check the Telerik API Analyzer and share your thoughts.
Back to Top
UI for WPF is Visual Studio 2017 Ready