Dynamically set property grid values

Hello,

I have a list of items that I want put into a property grid.  I have figured out how to set the name and category of each item in the property grid, but not the value.

Attached is a sample program showing my issue.  I am trying to populate the property grid in ViewModel.

PopulatePropertyGrid.  Could you please tell me what I need to do in order to populate the value?

Aaron


Attachment: EII.SF.PropertyGrid_e303750b.zip

10 Replies

SN Sudharsan Narayanan Syncfusion Team November 23, 2021 03:16 AM UTC

Hi Aaron

Thanks for contacting Syncfusion support,

We have checked the reported issue that “Dynamically set the value” from our end. We have prepared the sample to achieve the requirement by using view model class. So you can check the sample from the below location for the reference and for more details. We have attached the Property Grid Documentation link below,

Sample: https://www.syncfusion.com/downloads/support/forum/170576/ze/Nested_Properties-483796181

Documentation: https://help.syncfusion.com/wpf/propertygrid/getting-started

Please check the above sample and let me know your concerns on this. If we are misunderstood your query, please provide the details for your requirement. So that we can provide a solution as earlier and it will be helpful for us.

Regards,
Sudharsan



AP Aaron Pedigo November 23, 2021 04:12 PM UTC

Sudharsan,

Unfortunately, this sample does not help my case.

In my case, I don't know the structure of the model at compile time.

That is why my Model class has generic properties that are for the 

Syncfusion.Windows.PropertyGrid.PropertyGridItem.


Using this method, I was able to set the name and category, but not the value.


My overall goal is to populate the PropertyGrid with data which has a structure only known at run time.

I also want to be able to get the values from the PropertyGrid to save any changes that the user has made.

The important part is that the data structure is not known at compile time.


Aaron




SN Sudharsan Narayanan Syncfusion Team November 25, 2021 03:50 AM UTC

Hi Aaron,

Thanks for the update,

We have prepared the sample to achieve your requirement by populating the items in the Property Grid. So please find the sample from the below location,

Sample: https://www.syncfusion.com/downloads/support/forum/170576/ze/PropertyGridItemDefinition-1951913838


Please check with the above sample and let me know your concerns.


Regards,
 
Sudharsan


AP Aaron Pedigo November 29, 2021 04:06 PM UTC

Sudharsan,

This example still does not work for my scenario.

I cannot have a normal model class, because the property names are not known at run time.

This example still uses the model class to set the property values.

As you can see, the Model class in my example is based on the needs of the property grid, not the actual item being displayed in the property grid.

Is there a way to display data in a property grid when the properties are not known at compile time?

Aaron



SN Sudharsan Narayanan Syncfusion Team November 30, 2021 02:50 PM UTC

Hi Aaron, 
 
Thanks for the update. 
 
We have checked your requirement “Dynamically add property items to PropertyGrid” and you have tried to adding items to the PropertyItem collection and display values through it. PropertyItems property is working based on the properties of SelectedObject, without setting SelectedObject PropertyGrid cannot get the underlying value. So we suggest you to use ICustomTypeDescriptor to achieve your requirement. We have modified your sample to display the properties which is added dynamically and it can be downloaded from below link, 
 
 
In this sample, ModelTypeDescriptor is set as SelectedObject. ModelTypeDescriptor helps to separate the given information about the properties, and its values to the base class.   
 
public PropertyDescriptorCollection GetProperties() 
        { 
            List<CustomPropertyDescriptor> modelProperties = new List<CustomPropertyDescriptor>(); 
            foreach (var model in models) 
            { 
                var attributes = new List<Attribute>(); 
                if(!string.IsNullOrEmpty(model.Category)) 
                { 
                    var categoryAttribute = new CategoryAttribute(model.Category); 
                    attributes.Add(categoryAttribute); 
                } 
 
                modelProperties.Add(new CustomPropertyDescriptor(this, model.ID, model.Value.GetType(), model.Name, attributes.ToArray())); 
            } 
             
            return new PropertyDescriptorCollection(modelProperties.ToArray()); 
        } 
 
Please let us know whether the sample meets your requirement. If not, please provide some more details about your requirement, this will help us to provide solution at earliest. 
 
Regards,
Sudharsan



AP Aaron Pedigo December 2, 2021 01:51 AM UTC

Sudharsan,

This helped me get a lot further but now I need a little bit more.

I put some example PropertyGridItems in the ViewModel.

How do I put a minimum and maximum on some (but not all) integer properties using this system?

Aaron


Attachment: EII.SF.PropertyGrid_4ca53f9f.zip


SN Sudharsan Narayanan Syncfusion Team December 3, 2021 03:42 AM UTC

Hi Aaron,

Thanks for the update,

Currently, we are analyzing your reported issue. We will validate and update you on the details on or before 06th December 2021.

We appreciate your patience until then.

 
Regards,
Sudharsan
 



SN Sudharsan Narayanan Syncfusion Team December 3, 2021 02:52 PM UTC

Hi Aaron,

Thanks for the patience,

We have checked the reported issue that “Update Min/Max value for Int Property” from our end. We have prepared a sample to achieve the requirement by assigning the custom editor to Int properties to set the Min/Max value. So, please find the sample from the below location,

Sample: https://www.syncfusion.com/downloads/support/forum/170576/ze/EII.SF.PropertyGrid1976783611

Please check the sample and let me know
whether the sample meets your requirement If not, please provide the details about the requirement for the further.

Regards,
Sudharsan
 



AP Aaron Pedigo replied to Sudharsan Narayanan December 6, 2021 09:47 PM UTC

Sudharsan,


That is really close to what I need, but each of my properties can have their own min and max.

Is there a way to have the custom editor take in the min and max as parameters and the min and max specified in the PropertyGridItem?


Aaron



SN Sudharsan Narayanan Syncfusion Team December 8, 2021 02:55 AM UTC

Hi Aaron,

Thanks for the update,

We have checked the reported query “Set the min and max specified in the PropertyGridItem?
from our end. We have prepared the sample to achieve the requirement by setting the parameters to custom editor for assigning the min/max value. So, please find the sample from the below,

Sample: https://www.syncfusion.com/downloads/support/directtrac/general/ze/EII.SF.PropertyGrid-MinMax-440595035

Please check the above sample and let me know your concerns. If you still facing any issue, please provide more details about the requirement.

Regards,
Sudharsan
 


Loader.
Up arrow icon