views:

41

answers:

3

Hello,

I created a DataGridView and I Configured it! how I can save all what the user input in XML file (settings.xml)? so next time the user run the program it will read all the data and view it in the GridDataView

the data will not be that much, it is just some kind of settings!

I found allot of tutorials online, but they either does not work or using DataGrid !!!

Edit: is this really hard to do! I notice that people who ask this questions do not get a solution, in spite of the hard work the experts do to explain !!!!!

I want to learn it any link to a tutorial (That Works)?

A: 

You need to serialize your DataSource not DataGrid.

Create new DataTable, add columns, bound DataTable to DataGrid. Then use DataTable.WriteXml and DataTable.ReadXml to save and load xml.

Orsol
you mean BindingSource type ??
Data-Base
I've edited my answer.
Orsol
+1  A: 

Easiest way is to connect a DataSet as datasource and then save the dataset to xml and load the xml the next time.

    DataSet ds = new DataSet();
    //save the dataset as xml
    ds.WriteXml("your path to save the xml");

    //read the xml into your dataset
    ds.ReadXml("your path to save the xml");
Wouter Janssens - Xelos bvba
hello, and how to connect a DataSet as datasource !!!
Data-Base
grid.DataSource = ds;And you need to make sure that the columnnames of the dataset are the same as the DataField property of the DataSet Columns.
Wouter Janssens - Xelos bvba
Thanks, now I got it, thanks for "make sure that the columnnames of the dataset are the same as the DataField property of the DataSet Columns" :-)
Data-Base
A: 

the most easy way:

Private DataSet UserSettings(string pathofXML)
{
   DataSet ds = new DataSet();
   ds.ReadXml(pathofXML);
   return ds;
}

private void BindGrid()
{
   string pathOfXML = Application.StartupPath + @"\Settings.xml";
   gridview.DataSource = UserSettings(pathOfXML);
}
Amit Ranjan
I'm sorry guys, but I feel blocked, I do not know how to do it, dman, I feel really blocked!
Data-Base