Skip to content

Infragistics Community Forum / Desktop / Ultimate UI for Windows Forms / Bind dynamic object to a grid using binding list

Bind dynamic object to a grid using binding list

New Discussion
Ishan Gandhi
Ishan Gandhi asked on Sep 16, 2015 2:33 AM

Hi,

I have recently started working with the dynamic type which was introduced in .NET 4.0. For adding extencibuluty to my already preexisting classes I decided to make them dynamic. Now since the code involves a whole lot of legacy code, refactoring it is a big mess. So there are also some static properties as well.

Here is what my class looks like

public class Person: DynamicObject

{

#region static-properties

public string FirstName{get; set;}

public string LastName{get; set;}

public string FullName{get; set;}

#endregion

private Dictionary _properties;

}

I can add values to it as follows.

Person p = new Person();

p.FirstName = "Ishan";

p.LastName = "Gandhi";

dynamic dynPerson = Person;

dynPerson.Nationality = "Indian";

I want to be able to display these object on ultragrid, but for some reason these dynamic properties are not displayed. I can still see their values in debug mode.

P.S. I am using a bindinglist to bind to grid's datasource.

Since my project would involve many objects, is there another way we can bind these objects to the grid.

Regards

Ishan 

Sign In to post a reply

Replies

  • 0
    Brian Fallon
    Brian Fallon answered on Sep 14, 2015 8:52 PM

    I was not able to understand exactly how you are using dynamic types from the examples you listed here. Since you did mention "dynamic properties", I will go on the assumption that you have dynamically typed properties on your 'Person' object, and these properties are not appearing in the UltraGrid, i.e., columns are not created for them.

    The only thing I can think of that would explain that is that the scope of the property was not defined as public.

    In any case I attached a sample that demonstrates dynamic properties appearing as expected in the UltraGrid; please modify this sample to reproduce the problem you are describing and we will take a closer look.

    • 0
      Ishan Gandhi
      Ishan Gandhi answered on Sep 15, 2015 12:35 PM

      Hi Brian,

      Thanks for your reply, but this is not what i was trying to do. I  have attached a sample with what i am trying to do. I have added a class called Expando which has a dictionary that stores all the dynamic properties. Any class inheriting "Expando" can be used to be declare dynamic properties. With the property name added as the key and its value as Key-Value pair to this dictionary. The issue now is that when I am adding two objects of this class to binding list, the appropriate number of items are being added but the value of the object that was added first is replicated to all the rows.

      In the example, the two rows should have the value

      Row1 => Short 1 Trainee

      Row2 =>  Long 1 MyName

      but instead it shows

      Row1 => Short 1 Trainee

      Row2 =>  Short 1 Trainee

      Please suggest where am I going wrong

      • 0
        Brian Fallon
        Brian Fallon answered on Sep 15, 2015 3:26 PM

        I have to assume that you have attached the wrong sample here; this one has no class named 'Expando', and in fact nothing about it even remotely resembles the problem you describe here.

      • 0
        Ishan Gandhi
        Ishan Gandhi answered on Sep 15, 2015 4:41 PM

        Hi Brian,

        Sorry for the mistake, I have reattached the correct project

      • 0
        Brian Fallon
        Brian Fallon answered on Sep 15, 2015 10:21 PM

        The bug is in your DynamicPropertyDescriptor class.

        Your implementation of the GetValue method does not observe the value of the 'component' parameter, which in this scenario is not always the same as the value of the 'businessObject' member variable. I changed the implementation to use the component parameter instead, and the second row appeared correctly.

      • 0
        Ishan Gandhi
        Ishan Gandhi answered on Sep 16, 2015 2:33 AM

        Hi Brian,

        Thanks it worked like a charm.

        Regards

        Ishan Gandhi

  • You must be logged in to reply to this topic.
Discussion created by
Favorites
Replies
Created On
Last Post
Discussion created by
Ishan Gandhi
Favorites
0
Replies
6
Created On
Sep 16, 2015
Last Post
10 years, 5 months ago

Suggested Discussions

Tags

Created by

Created on

Sep 16, 2015 2:33 AM

Last activity on

Sep 16, 2015 2:33 AM