Infering a DataSet from a DataGridView RRS feed

  • Question

  • Hi,
    I have a Windows Forms application that contains a DataGridView.  I've already defined all the columns just the way I want them in the Designer.  Now assume the user adds a bunch of rows to the DataGridView; I want a way to be able to save this DataGridView's contents to a file.  I know that a DataSet supports the WriteXml method, but how do I get a DataSet from a DataGridView, other than through some manual means?


    Edit: I should mention that I don't care if I use a DataSet or not; the important part is having a straightforward way of importing data into the DataGridView and exporting it to a file.
    Friday, December 21, 2007 12:06 AM


All replies

  • If the DataGridView is databound you can access the provider via the DataSource property...
    Otherwise, i'm affraid you'll have to manually iterate over the cells... (An example of this: )
    Friday, December 21, 2007 9:23 AM

    Hmm, no problem, thank you.  That actually puts my mind at ease to know that that's an acceptable way to do it.  I mainly wanted to make sure I wasn't missing a better solution.




    Friday, December 21, 2007 11:26 PM