views:

714

answers:

2

I have an XML File:

    <Database>
    <SMS>
    <Number>+447761692278</Number>
    <DateTime>2009-07-27T15:20:32</DateTime>
    <Message>Yes</Message>
    <FollowedUpBy>Unassigned</FollowedUpBy>
    <Outcome></Outcome>
    <Quantity>0</Quantity>
    <Points>0</Points>
   </SMS>
   <SMS>
    <Number>+447706583066</Number>
    <DateTime>2009-07-27T15:19:16</DateTime>
    <Message>STOP</Message>
    <FollowedUpBy>Unassigned</FollowedUpBy>
    <Outcome></Outcome>
    <Quantity>0</Quantity>
    <Points>0</Points>
    </SMS>
    </Database>

Currently I read it into a datagridview using this:

public void Read()
     {
      DataSet ds = new DataSet("SMS DataSet");
      XmlDataDocument xmlDatadoc = new XmlDataDocument();
      xmlDatadoc.DataSet.ReadXml(@"C:\Documents and Settings\Administrator\Desktop\RecSmsDB.xml");
      ds = xmlDatadoc.DataSet;
      this.dataGridView1.DataSource = ds;
      this.dataGridView1.DataMember = "SMS";
      this.dataGridView1.Sort(dataGridView1.Columns["DateTime"], ListSortDirection.Descending);
     }

I want to be able to only read in the xml objects that have a specific DateTime. Does anyone know of a way of doing this? Currently I have tried a variety of the methods included in the namespace but to no avail.

Help greatly appreciated,

regards.

***EDIT: I want to be able to dynamically change the data displayed at run time.

+4  A: 

Not that I can think of. However, you can read all the data into the DataSet, then create a DataView which filters the SMS table, and bind your grid to that instead of the DataTable.

Christian Hayter
+1 Agreed. Unless the data is prohibitively large, just filter it in the DataSet.
Richard Szalay
+1  A: 

What if you attach the DataSet to a BindingSource and attach this BindingSource to the grid? A BindingSource has a Filter property where you can enter SQL-like expressions.

Scoregraphic