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

Browsable Property not working as expected

9 Answers 315 Views
PropertyGrid
This is a migrated thread and some comments may be shown as answers.
Dharmavaram
Top achievements
Rank 1
Dharmavaram asked on 19 Sep 2016, 06:41 AM

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.

     

 

9 Answers, 1 is accepted

Sort by
0
Dilyan Traykov
Telerik team
answered on 19 Sep 2016, 12:35 PM
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.
0
Dharmavaram
Top achievements
Rank 1
answered on 20 Sep 2016, 04:23 AM

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.

 

0
Dilyan Traykov
Telerik team
answered on 20 Sep 2016, 09:58 AM
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.
0
Dharmavaram
Top achievements
Rank 1
answered on 26 Sep 2016, 09:19 AM

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.

0
Dilyan Traykov
Telerik team
answered on 27 Sep 2016, 12:53 PM
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.
0
Dharmavaram
Top achievements
Rank 1
answered on 28 Sep 2016, 03:42 AM

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

0
Dilyan Traykov
Telerik team
answered on 28 Sep 2016, 10:28 AM
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.
0
Dharmavaram
Top achievements
Rank 1
answered on 28 Sep 2016, 12:50 PM

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??

0
Dilyan Traykov
Telerik team
answered on 29 Sep 2016, 01:51 PM
Hello Dharmavaram,

Another approach would be to handle the PropertyChanged event of your bound item, and call the ReloadData method 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.
Tags
PropertyGrid
Asked by
Dharmavaram
Top achievements
Rank 1
Answers by
Dilyan Traykov
Telerik team
Dharmavaram
Top achievements
Rank 1
Share this question
or