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
970
FieldLayouts issue example code in WPF 2011.1
posted

What's wrong here?  This will not show any values unless you uncomment the 2 lines, or uncomment the 2 lines and add more data too get 2 lines of data.

           ObservableCollection<string> FieldValue;
            ObservableCollection<ObservableCollection<string>> tableValues = new ObservableCollection<ObservableCollection<string>>();
            xamDataGrid1.FieldLayoutSettings.AutoGenerateFields = false;

            xamDataGrid1.FieldLayouts.Add(BuildHeader("FirstName", "LastName", "Age"));

            FieldValue = new ObservableCollection<string> { "John", "Doe", "19" };
            tableValues.Add(FieldValue);


            //FieldValue = new ObservableCollection<string>();
            //tableValues.Add(FieldValue);

        private FieldLayout BuildHeader(params string[] headers)
        {
            FieldLayout fldLayout = new FieldLayout();
            for (int i = 0; i < headers.Count(); i++)
            {
                string s = headers[i];
                UnboundField uf = new UnboundField();
                uf.Name = s;
                uf.Label = s;
                uf.BindingPath = new PropertyPath("Items[" + i.ToString() + "]", null);
                fldLayout.Fields.Add(uf);
            }
            return fldLayout;
        }

            xamDataGrid1.DataSource = tableValues;

 

 

 

Parents
No Data
Reply
  • 30945
    Offline posted

    Hello,

     

    Thank you for your patience during the investigation of this behavior. After researching it, our Development Team concluded that this behavior is by design. When the data source is an IList with a single item that is an IEnumerable the XamDataGrid binds to the item instead of the outer list. This done in order to handle certain types of data sources.

     

    You can avoid this behavior by wrapping your data source (ObservableCollection< ObservableCollection<string>>) to a list and use that list as data source for the XamDataGrid. Here is an example for doing so:

     

    ArrayList wrapperList = new ArrayList();

    wrapperList.Add(tableValues);

    xamDataGrid1.DataSource = wrapperList;

     

    I have also created a sample application that demonstrates how this behavior can be avoided.

     

    If you have any further questions on the matter please do not hesitate to ask.

     

    Sincerely,

    Krasimir

    Developer Support Engineer

    Infragistics

    www.infragistics.com/support

    TestApp1.zip
Children
No Data