Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
135
Setting the UnboundField.BindingPath to a specific EntityCollection element
posted

Hi!

I am trying to customize the layout of xamDataGrid programmatically by creating custom FieldLayouts with a colection of UnboundFields.

 This approach works fine until i try to set the BindingPath property to an element of the System.Data.Objects.DataClasses.EntityCollection. This collection type does not support index-based iteration and provides the 'ElementAt' method to access specific elements.

I tried to set the binding as

1) UnboundField.BindingPath = new PropertyPath("[0].Value");

2) UnboundField.BindingPath = new PropertyPath("ElementAt(0).Value");

However none of this worked.

I alo tried a different approach - assigning values to cells in the InitializeRecord event. However this time the grid seemed to slow down and the cell value remained unchanged no matter what i did.

I would be most grateful if you could help me with the BindingPath issue.

Parents
No Data
Reply
  • 69686
    posted

    Hello,

    I do not think that this approach would give you the result you want. You can easily go around this problem by handling the FieldLayoutInitialized event. Here is one way to do this:

    void xamDataGrid1_FieldLayoutInitialized(object sender, Infragistics.Windows.DataPresenter.Events.FieldLayoutInitializedEventArgs e)

            {

                List<string> fields = new List<string>();

                foreach (Field field in e.FieldLayout.Fields)

                {

                    if (field.IsExpandableResolved == false)

                    {

                        fields.Add(field.Name);

                    }

                }

                e.FieldLayout.Fields.Clear();

                foreach (string s in fields)

                {

                    UnboundField ub = new UnboundField();

                    ub.Name = s;

                    ub.Label = "Label of" + s + "Field";

                    ub.BindingPath = new PropertyPath(s);

                    e.FieldLayout.Fields.Add(ub);

                }

                (sender as XamDataGrid).FieldLayoutSettings.AutoGenerateFields = false;

            }

    Let me know if you have any questions on this.

    Regards,

    Alex.

Children