Lee Barry:
I have tried to read/save xml file to Datagrid and I'm using Dataset to do it. Now I have succeed to load xml file data to datagrid, the code as follows:
public class StoreDbDataSet
{
public DataTable GetProducts()
{
return ReadDataSet().Tables[0];
}
internal static DataSet ReadDataSet()
{
DataSet ds = new DataSet();
ds.ReadXmlSchema("store.xsd");
ds.ReadXml("store.xml");
return ds;
}
}
And:
public class StoreDb
{
public ObservableCollectionGetProducts()
{
DataSet ds = StoreDbDataSet.ReadDataSet();
ObservableCollectionproducts = new ObservableCollection ();
foreach (DataRow productRow in ds.Tables["Products"].Rows)
{
products.Add(new Product((string)productRow["ModelNumber"],
(string)productRow["ModelName"], (string)productRow["InputAddress"],
(string)productRow["OutputAddress"], (string)productRow["DiagAddress"],
(string)productRow["Description"], (byte)productRow["CategoryID"],
(string)productRow["CategoryName"], (string)productRow["ProductImage"]));
}
return products;
}
}
Xaml File:
The ViewModel:
public ICollectionView ProductsView
{
get { return _ProductsView; }
set
{
_ProductsView = value;
NotifyPropertyChanged();
}
}
My question is when I changed the datagrid data, how can I save the changes to xml?Thanks in advance!
Posted in S.E.F
via StackOverflow & StackExchange Atomic Web Robots
This Question have been answered
HERE