Reputation: 2321
I have a design question that has to do with saving the contents of my datagridview. I don't have a binding source or anything, what I want is to save its contents to a file (can be of any type or form), but then give the user the ability to open that file and load the saved grid contents back in. While the application is open, the user is adding/editing/deleting columns or whatever. I've seen some questions on saving the contents as an Excel table. Is this the best way to go?
Maybe the datagridview isn't designed for this, but if there's something better, please let me know.
Upvotes: 1
Views: 1018
Reputation: 6971
put all your data in a datatable and then bind it to the datagridview when you are ready to save it do this
DataTable dt = ((DataView)this.dataGridView1.DataSource).Table;
dt.WriteXml(@"C:\test\text.xml");
http://social.msdn.microsoft.com/Forums/en-US/winforms/thread/cd4d2fb0-97a4-4b17-96fc-9ca6992456cc/
Upvotes: 1