Skip to content

Archive for August, 2012


WPF DataGrid Dilemma: Add Column to Bound DataTable

Well after many hours of being stumped and perusing the web; I finally have a solution to my dilemma surrounding the WPF DataGrid.

It seemed like a simple problem: Bind a DataGrid to a DataTable and have it update all it’s contents both ways. Getting the initial content worked like a charm, but then trying to add a new column to add new data wasn’t working at all. It was a nightmare and I any example I found just stopped at loading initial data in.

It turns out that while the DataTable behind is happy to update itself and other things bound to it will update their collections, even with AutoGenerateColumns set to true, the DataGrid just happily ignores the new column and doesn’t display a thing.

The solution I finally came upon requires that you create your own column on the DataGrid to bind back to the column added in the DataTable.

Read moreRead more