From ListView to DataSet

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • geng

    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
    InvalidCastExce ption. 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(D ataFile,
    System.Text.Enc oding.Unicode);
    data.WriteXml(W riter,XmlWriteM ode.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
    (InvalidCastExc eption)..
    Thanks in advance !



    *** Sent via Developersdex http://www.developersdex.com ***
Working...