From ListView to DataSet

G

geng

Hello everyone !

As you can see I am new to this. It is also my first post! I have a
visual c# pocket pc form with a listview in it. The listview has one
column at the moment and it is populated by using a textbox and a
button. I am trying to save to contents of the listview to an Xml file.

I have the following code and the debugger gives me no errors, but when
I am trying to save on the pocket pc or the emulator I get
InvalidCastException. I guess that the problem is when I convert the
listview to the dataset but I can’t figure it out. I would really
appreciate your input.

DataSet data = new DataSet();
DataGrid dg = new DataGrid();
dg.DataSource = listView1.Items;
data = (DataSet) dg.DataSource;

and then save the data like:

Writer = new XmlTextWriter(DataFile,
System.Text.Encoding.Unicode);
data.WriteXml(Writer,XmlWriteMode.WriteSchema);
Writer.Close();

There is a lot of info on how to populate a datagrid or listview from an
xml using a dataset. But how can I do the opposite ?? The datagrid does
take the data from the list but the conversion to dataset gives errors
(InvalidCastException)..
Thanks in advance !
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top