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,
I have been looking into your post and I am not completely sure what you are trying to achieve using the code snippet that you have posted. Would you please give me more detailed description of how the approach that you are implementing is supposed to behave and the appearance of the XamDataGrid that you are expecting to achieve using the code snippet that you have posted?
Looking forward to hearing from you.
Sincerely,
Krasimir
Developer Support Engineer
Infragistics
www.infragistics.com/support
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?