I am implementing my own blank row to display at the end of the grid where users will be allowed to enter new data.
I do this by adding an empty row to the end of my ItemsSource
The issue is on Filtering and Sorting the empty row is included in the action. I tried removing the row and then re-adding it on the Filtering/Filtered and Sorting/Sorted events but on re-add the item is added to the sorted position not the end of the grid. Any help?
For reference this is how I set my DataContext for the Grid.
Add and Unload Empty Row
I do this by adding an empty row to the end of my ItemsSource
The issue is on Filtering and Sorting the empty row is included in the action. I tried removing the row and then re-adding it on the Filtering/Filtered and Sorting/Sorted events but on re-add the item is added to the sorted position not the end of the grid. Any help?
For reference this is how I set my DataContext for the Grid.
public DataTable CurrentDataTable { get { return dataGridView.ItemsSource != null ? ((BindingSource) dataGridView.ItemsSource).DataSource as DataTable : null; } set { CurrentSelectedTableName = value.TableName; //BindingSource to sync DataTable and DataGridView var bSource = new BindingSource {DataSource = value}; //set the DataGridView DataSource dataGridView.DataContext = bSource; } }Add and Unload Empty Row
public void LoadExtraRow() { var itemSourceDataTable = CurrentDataTable; if (itemSourceDataTable == null) return; var newRow = itemSourceDataTable.NewRow(); newRow.RowError = "NEW_ROW"; itemSourceDataTable.Rows.Add(newRow); dataGridView.Rebind(); } public void UnloadExtraRow(){ var itemSourceDataTable = CurrentDataTable; if (itemSourceDataTable == null) return; if (itemSourceDataTable.Rows.Count > 0) { var emptyRowToRemove = itemSourceDataTable.Rows[itemSourceDataTable.Rows.Count - 1]; if (emptyRowToRemove.RowError == "NEW_ROW") { itemSourceDataTable.Rows.Remove(emptyRowToRemove); } } }