I have a DataTable that I create on the fly, and orginally I put 10 columns in it and it binds to the datagrid with the DataSource property.
However, the user than has the option to increase or decrese the column, when the user selects to increase the column count greater than the original column count ( like going from 10 to 15), I can create the new DataTable and increase the columns in it, but when I bind the new DataTable to the DataGrid, I only get the first 10 columns. The grid seems to ignore the other 5 columns.
The data in the first 10 columns is updated to the new DataTables data, but for some reason it wont increase the number of columns past the orginal amount.
My binding is as simple as
this.DataGrid.DataSource = null;
this.DataGrid.DataSource = dataTable.Rows;
Anyone seen this or know how I can resolve this ?
Thanks
DK
Hi DK,
I just tried this out and I can't reproduce the issue. Maybe it's an issue that was fixed recently or something specific to your sample that's causing it. One thing you can try is clear the FieldLayouts collection on the data grid right before setting the data source to the new table. This should cause the data grid to recreate the field layouts based on the new data source and include all the columns.
Hope this helps,
Sandip
Hey Sandip,
I tried what you said to do a this.DataGrid.FieldLayouts.Clear();
When I set the new DataTable.Rows to the DataSource of the grid now, I get the following exception:
System.NullReferenceException: Object reference not set to an instance of an object.
at Infragistics.Windows.DataPresenter.DataPresenterBase.OnPropertyChanged(DependencyPropertyChangedEventArgs e)\r\n at Infragistics.Windows.DataPresenter.XamDataGrid.OnPropertyChanged(DependencyPropertyChangedEventArgs e)\r\n at System.Windows.DependencyObject.NotifyPropertyChange(DependencyPropertyChangedEventArgs args)\r\n at System.Windows.DependencyObject.UpdateEffectiveValue(EntryIndex entryIndex, DependencyProperty dp, PropertyMetadata metadata, EffectiveValueEntry oldEntry, EffectiveValueEntry& newEntry, Boolean coerceWithDeferredReference, OperationType operationType)\r\n at System.Windows.DependencyObject.SetValueCommon(DependencyProperty dp, Object value, PropertyMetadata metadata, Boolean coerceWithDeferredReference, OperationType operationType, Boolean isInternal)\r\n at System.Windows.DependencyObject.SetValue(DependencyProperty dp, Object value)\r\n at Infragistics.Windows.DataPresenter.DataPresenterBase.set_DataSource(IEnumerable value)\r\n at JDA.SCPO.SKUModule.Views.SKUProjection.SKUProjectionView.SetSKUProjectionDataGrid(DataTable skuProjectionDataTable) in C:\\Release\\v75\\SCPO\\JDAVSNET\\Source\\SCPOWin\\SKUModule\\Views\\SKUProjection\\SKUProjectionView.xaml.cs:line 78\r\n at JDA.SCPO.SKUModule.Views.SKUProjection.SKUProjectionViewPresenter.CreateSKUProjectionDataSet(DateTime startDate, Int32 periodicity, Int32 weeksToDisplay) in C:\\Release\\v75\\SCPO\\JDAVSNET\\Source\\SCPOWin\\SKUModule\\Views\\SKUProjection\\SKUProjectionViewPresenter.cs:line 132"
I've just tried this code out and I don't get any exceptions. Also for me it works without the call to FieldLayouts.Clear. My guess is that this is something that may have already been fixed. You should try the latest hotfix and if the issue still happens than you should report it to infragistics support at http://es.infragistics.com/gethelp. This way if there's something specific to your app that's causing the issue, they can look at it.
private DataTable CreateTable( int cols ){ DataTable dt = new DataTable( ); for ( int i = 0; i < cols; i++ ) { dt.Columns.Add( "Col " + i ); } dt.Rows.Add( new object[ { "test" } ); return dt;}public void btn_Click( object sender, RoutedEventArgs e ){ this.dp.FieldLayouts.Clear( ); this.dp.DataSource = this.CreateTable( 15 ).Rows;}