1

I'm having a rough time deleting a column of data in my datagrid and having that deletion propagate to my data source. I've implemented the solution for binding data found in this SO thread, and am using this code to delete my column:

vizDataGrid.Columns.Remove(cell.Column);

What's happening is that the UI shows the column being deleted, but when I go add a column, the column I thought I had just deleted appears (or at least the data that was inside that column does). Any help would be greatly appreciated, I've been at this for days (WinForms was so much simpler!). Thanks!

Community
  • 1
  • 1
GGCO
  • 183
  • 5
  • 12

1 Answers1

0

It is because of AutoGenerateColumns="True". Set it false and add columns on your own in code behind.

Please check this SO post to dynamically adding columns to a DataGrid.

Community
  • 1
  • 1
Nitesh
  • 7,261
  • 3
  • 30
  • 25
  • Ok awesome, thanks. One thing real quick though - how would I go about handling adding rows? Could I still use the Bindable Dynamic Dictionary or would I have to do something else? I have dynamic data (CSV file) and won't know how many columns I have so I'm limited by that. – GGCO Jul 31 '13 at 05:45
  • If you check the link I provided in answer, you can see how to find number of columns from your data source. Regarding to rows, you just bind your data source to `ItemsSource` property of `DataGrid` and WPF will generate them for you. If you want to add another row then create a new data item and add it your data source. – Nitesh Jul 31 '13 at 06:18
  • I understand that, I'm building out the columns right now by parsing the CSV and counting the number of items on a line. For rows, I thought I'd iterate over each line and create a `DataGridRow` object. I'm stuck at the part where I populate the row with the appropriate data from the specific line in my CSV file (represented as an array in my code right now). So I think my issue is how do I bind my data source to the `ItemsSource` property? – GGCO Jul 31 '13 at 06:39