WPF DataGrid - XML

Mar 5, 2009 at 5:31 AM

I'm new to WPF and newer still to the WPF DataGrid.  In a C# WinForms app. I added a DataSet to my project and then added several DataTables to that DataSet.  Neither the DataSet nor the DataTables are linked to a DataBase.  I have a DataGrid on my form that has its DataSource set to my DataSet and the DataMember set to one of my DataTables.  When I add data to my DataGrid and I want to save that data, I click a save button that simply writes the contents of my DataTable that is the DataMember of my DataGrid to an xml file like this: 




void btnSave_Click(object sender, EventArgs e)











 Its very simple and works great.  So I decide I want to learn WPF and decide that I want to use the new WPF DataGrid in a test app. Well, I've managed to get a DataTable from my DataSet linked to a WPF DataGrid so I can see all the columns of the grid at design time.  However, I try writing the data to an xml file just like I did in my winforms project and nothing happens.  I can't tell if the underlying DataTable isn't getting data or if the DataTable has the data but isn't writing it to my xml file.  Can anyone please help me to understand how I can make this work?  Thank you!

Mar 5, 2009 at 7:15 AM
I would start with finding out whether or not the DataTable actually has your data. Assuming VS 2008, in debug mode, hover over the DataSet instance variable, then navigate to the DataTable (in the Tables collection) and further to non-public members, rowCollection, non-public members, list, Results View, then any DataRow, and finally ItemArray. That will tell you exactly what is in the DataTable itself. If you need to map between columns indexes and names, look at the DataTable's Columns collection.