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;
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
I have logged this behavior with our developers in our tracking system, with an issue ID of 98246. I have also created a support ticket on your behalf with number CAS-79527-26K4RH in order to link the development issue to it so that you are automatically updated when a Service Release containing your fix is available for download.
Infragistics, Inc.
Thanks for the update
I have further investigated the issue that you have described and I have contacted our development team for mode detailed information on the matter. I will update you as soon as I have feedback from them.
Thank you for your patience.
You would need to build it to understand my question, as it will become blatantly obvious. I just rebuilt the project from scratch.
Start a new WPF project, add XamDataGrid, add this code
using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Windows;using System.Windows.Controls;using System.Windows.Data;using System.Windows.Documents;using System.Windows.Input;using System.Windows.Media;using System.Windows.Media.Imaging;using System.Windows.Navigation;using System.Windows.Shapes;
using System.Collections.ObjectModel;using Infragistics.Windows.DataPresenter;
namespace WpfApplication15{ /// <summary> /// Interaction logic for MainWindow.xaml /// </summary> public partial class MainWindow : Window { public MainWindow() { InitializeComponent(); }
private void Window_Loaded(object sender, RoutedEventArgs e) { 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);
xamDataGrid1.DataSource = tableValues; }
}}
Where did John Doe go?
Now uncomment the 2 lines that are commented, build, run.
Why does this work?
I have a datasource that will have unknown data in it. Anywhere from 2 to 255 columns of data. Anywhere from zero to 40,000 records. I need something to bind to the grid, that works without knowing anything about the data. For my testing I use zero records, one record, and many records.
Like I said I have a work around, but am not sure why I should have to work around this.
So my real question is... What am I doing wrong?