Writing back to XML file using Treeview

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I am populating a treeview in a smart device application with data from an XML file. I’m doing so through a dataset, using the Dataset.ReadXML method. I have done this successfully, but am now having trouble updating my XML file with any changes that I have made. To give you an example, if I click on a node in my treeview, a new screen pops up with that node’s attributes. I want to be able to edit those attributes and then save my changes back into the XML file. I know that this can easily be done with a bound control like a listview and textbox, and then simply calling the Dataset.WriteXML method, but the treeview isn’t as easily data bound.

Does anyone have any idea how this can be done, and if so, please can you help me with some example code.
 
I also use xml files to store my data and bind it to most of my controls.
There are controls which I manually update (i.e. they are not bound). So
when those are changed I do the following :

DataRow[] rowToEdit = customersTable.Select(selectString);
rowToEdit[0]["emailAddress"] = txtBox.text.ToString();

So, I first select the datarow according to a search string. In my case I do
a search for the ordernumber because it's always unique (to ensure that the
data row object will always only contain one row). Once I have a datarow I
can just edit any field in it. At the end I just do a WriteXml to write the
changes in the DataSet back to the xml file.

in short:

1) create a datarow
2) do a select with some kind of unique field
3) update the datarow with the new data that comes from your TreeView
4) write back the dataset to the xml file

I can't unfortunately be precise about getting data from a treeview because
I haven't myself worked with it.

jez

Cuervo said:
I am populating a treeview in a smart device application with data from an
XML file. I'm doing so through a dataset, using the Dataset.ReadXML method.
I have done this successfully, but am now having trouble updating my XML
file with any changes that I have made. To give you an example, if I click
on a node in my treeview, a new screen pops up with that node's attributes.
I want to be able to edit those attributes and then save my changes back
into the XML file. I know that this can easily be done with a bound control
like a listview and textbox, and then simply calling the Dataset.WriteXML
method, but the treeview isn't as easily data bound.
Does anyone have any idea how this can be done, and if so, please can you
help me with some example code.
 
It works! Thank you thank you thank you! You rock!

jez said:
I also use xml files to store my data and bind it to most of my controls.
There are controls which I manually update (i.e. they are not bound). So
when those are changed I do the following :

DataRow[] rowToEdit = customersTable.Select(selectString);
rowToEdit[0]["emailAddress"] = txtBox.text.ToString();

So, I first select the datarow according to a search string. In my case I do
a search for the ordernumber because it's always unique (to ensure that the
data row object will always only contain one row). Once I have a datarow I
can just edit any field in it. At the end I just do a WriteXml to write the
changes in the DataSet back to the xml file.

in short:

1) create a datarow
2) do a select with some kind of unique field
3) update the datarow with the new data that comes from your TreeView
4) write back the dataset to the xml file

I can't unfortunately be precise about getting data from a treeview because
I haven't myself worked with it.

jez

Cuervo said:
I am populating a treeview in a smart device application with data from an
XML file. I'm doing so through a dataset, using the Dataset.ReadXML method.
I have done this successfully, but am now having trouble updating my XML
file with any changes that I have made. To give you an example, if I click
on a node in my treeview, a new screen pops up with that node's attributes.
I want to be able to edit those attributes and then save my changes back
into the XML file. I know that this can easily be done with a bound control
like a listview and textbox, and then simply calling the Dataset.WriteXML
method, but the treeview isn't as easily data bound.
Does anyone have any idea how this can be done, and if so, please can you
help me with some example code.
 
glad to hear it works:)

just as a side point but of interest :

There's an interesting news-thread about XML. I've learned quite a bit about
XML performance by reading it and I would next time think twice before using
xml files.. Xml is pretty good when working with relatively small files but
have a look at the following two threads. Maybe next time you should
consider using SqlCe or CSV files (OpenNetCF made an adapter to read
these!). I'm still using xml files myself because the files aren't too big
(on avg. 50K) and it's pretty easy, but have a look at these threads!

Xml VS Csv
http://groups.google.com/groups?hl=...c.dotnet.framework.compactframework&scoring=d

Xml VS SqlCe
http://groups.google.com/groups?hl=...soft.public.dotnet.framework.compactframework

Cuervo said:
It works! Thank you thank you thank you! You rock!

jez said:
I also use xml files to store my data and bind it to most of my controls.
There are controls which I manually update (i.e. they are not bound). So
when those are changed I do the following :

DataRow[] rowToEdit = customersTable.Select(selectString);
rowToEdit[0]["emailAddress"] = txtBox.text.ToString();

So, I first select the datarow according to a search string. In my case I do
a search for the ordernumber because it's always unique (to ensure that the
data row object will always only contain one row). Once I have a datarow I
can just edit any field in it. At the end I just do a WriteXml to write the
changes in the DataSet back to the xml file.

in short:

1) create a datarow
2) do a select with some kind of unique field
3) update the datarow with the new data that comes from your TreeView
4) write back the dataset to the xml file

I can't unfortunately be precise about getting data from a treeview because
I haven't myself worked with it.

jez

Cuervo said:
I am populating a treeview in a smart device application with data
from an
XML file. I'm doing so through a dataset, using the Dataset.ReadXML method.
I have done this successfully, but am now having trouble updating my XML
file with any changes that I have made. To give you an example, if I click
on a node in my treeview, a new screen pops up with that node's attributes.
I want to be able to edit those attributes and then save my changes back
into the XML file. I know that this can easily be done with a bound control
like a listview and textbox, and then simply calling the Dataset.WriteXML
method, but the treeview isn't as easily data bound.
Does anyone have any idea how this can be done, and if so, please can
you
help me with some example code.
 
Back
Top