Binding to class in GridTemplateColumn

Hi.

I have a small problem, and that is that I have a list of objects X and in it I have object Y. When I bind this object Y via MappingName, ValueBinding to TemplaterSelector always comes null. To illustrate this more, I have a Shopping object and in it I have a Discount object. How can I get to this discount object ?


1 Reply

MS Malini Selvarasu Syncfusion Team September 19, 2024 10:01 AM UTC

Hi Sebastian Kowalewski,

Based on the information provided, it appears that you are trying to bind the Discount object to a GridTemplateColumn, but are encountering an issue where the ValueBinding in the TemplateSelector returns null.
Upon reviewing your code snippet, we noticed that you have attempted to bind the Discount object through the ViewModel. However, since you mentioned that the Discount object resides within the ShoppingObject class, it is crucial to correctly configure the DisplayBinding path to access the Discount object. The binding operates based on the DataContext of the GridCell. If the bound property (Discount) is part of the Shopping Object class, the value will be retrieved; otherwise, it will return null.
We recommend ensuring that both the DisplayBinding and ValueBinding are correctly set with the appropriate path. This will guarantee that the values are accurately bound and displayed. To further assist you, we have prepared a sample demonstrating this approach. Please review it and let us know if it aligns with your requirements.
If we have misunderstood your request or if your needs differ, kindly provide additional details regarding the issue you are facing. This will enable us to better understand the problem and offer a suitable solution.
Thank you for your understanding and cooperation.
Regards,
Malini Selvarasu

Attachment: SfDataGrid_Demo_6de82af7.zip

Loader.
Up arrow icon