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;