469,958 Members | 2,035 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,958 developers. It's quick & easy.

From ListView to DataSet

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 !

*** Sent via Developersdex http://www.developersdex.com ***
Nov 17 '05 #1
0 2766

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by ExDelphi | last post: by
reply views Thread by Bom | last post: by
4 posts views Thread by microsoft.news.com | last post: by
4 posts views Thread by Lasse Eskildsen | last post: by
1 post views Thread by Mike | last post: by
4 posts views Thread by IfThenElse | last post: by
reply views Thread by rainxy | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.