1

我有一个 XML 文件:

    <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>

目前我使用这个将它读入datagridview:

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);
        }

我希望能够只读取具有特定日期时间的 xml 对象。有谁知道这样做的方法?目前我已经尝试了命名空间中包含的各种方法,但无济于事。

非常感谢帮助,

问候。

***编辑:我希望能够动态更改运行时显示的数据。

4

2 回答 2

4

不是我能想到的。但是,您可以将所有数据读入 DataSet,然后创建一个过滤 SMS 表的 DataView,并将您的网格绑定到该数据表而不是 DataTable。

于 2009-07-28T11:44:40.773 回答
1

如果将 DataSet 附加到 BindingSource 并将此 BindingSource 附加到网格会怎样?BindingSource 有一个 Filter 属性,您可以在其中输入类似 SQL 的表达式。

于 2009-07-28T11:48:26.803 回答