Binding of indexed property

Posted by: gennadiy_lenivenko on 29 December 2019, 9:36 pm EST

  • Posted 29 December 2019, 9:36 pm EST

    I am trying to bind child collection to FlexGrid e.g.
    ------------------------
    ...
    public class MyParentClass {
    public string Id {get;set;}
    public List<MyChildClass> Children {get;}
    }

    public class MyChildClass {
    public string Name {get;set;}
    }
    ...
    <GridColumn Binding="Id" Header="Id" >
    for (int i = 0; i < 3; i++)
    {
    int j = i;
    <GridColumn Binding=@("Children["+j+"].Name") Header=@("Name" + j) />
    }
    ...
    ------------------------
    But I cannot see anything except data in the first column
    Is this limitation of control or I made a mistake?
    Thank you
  • Marked as Answer

    Replied 30 December 2019, 1:49 pm EST

    Hi,
    The code snippet provided by you seems OK and it should work. We tried the same and it works for us with the build version: 3.1.20193.434.

    Please refer to the following code and the attached sample for reference.
    <FlexGrid ItemsSource="TreeItems" AutoGenerateColumns="false">
    <FlexGridColumns>
    <GridColumn Binding="ID"></GridColumn>
    <GridColumn Binding="Name"></GridColumn>
    @for (int i = 0; i < TreeItems[0].Children.Count; i++)
    {
    <GridColumn Binding=@("Children["+i+"].Name") Header=@("Child"+(i+1)+" Name")></GridColumn>
    }
    </FlexGridColumns>
    </FlexGrid>

    @code{
    List<Tree> TreeItems = Tree.GetData(5);
    }


    Just for information, assigning i to variable j is not useful in this case. You may avoid the line of code.

    Hope it helps!

    Regards,
    Manish Gupta


    FlexGrid-DynamicColumnBinding.zip
  • Replied 3 January 2020, 6:24 am EST

    Thank you, Mr. Manish,
Need extra support?

Upgrade your support plan and get personal unlimited phone support with our customer engagement team

Learn More

Forum Channels