C#-将XML文件的特定元素读取到dataGridView中,并在文本框中显示其余部分

本文关键字:文本 显示 余部 dataGridView 文件 XML 读取 元素 C#- | 更新日期: 2023-09-27 18:22:04

嗨,我遇到了一个问题,我想得到一些帮助。首先,我在这里有一个XML文件

    <data>
<row>
  <id>1</id>
  <description>description 1</description>
  <thedate>2013-06-12T00:00:00</thedate>
  <somenotes>some notes1asdsadsadsad</somenotes>
</row>
<row>
  <id>2</id>
  <description>description 2</description>
  <thedate>2013-06-15T00:00:00</thedate>
  <somenotes> </somenotes>
</row>
<row>
  <id>3</id>
  <description>description 3</description>
  <thedate>2013-06-21T00:00:00</thedate>
  <somenotes>bobobobojkfjh</somenotes>
</row>
<row>
  <id>4</id>
  <description>description 4</description>
  <thedate>2013-06-17T00:00:00</thedate>
  <somenotes>adaad</somenotes>
</row>
<row>
  <id>5</id>
  <description>description 5</description>
  <thedate>2013-06-24T00:21:04.803</thedate>
  <somenotes>zcxzc</somenotes>
</row>
<row>
  <id>6</id>
  <description>description 6</description>
  <thedate>2012-12-01T00:00:00</thedate>
  <somenotes>ssss</somenotes>
</row>
<row>
  <id>7</id>
  <description>description 11</description>
  <thedate>2013-05-16T00:21:04.803</thedate>
  <somenotes> </somenotes>
</row>
<row>
  <id>8</id>
  <description>description 21</description>
  <thedate>2013-05-07T00:00:00</thedate>
  <somenotes>notes 2</somenotes>
</row>
<row>
  <id>9</id>
  <description>description 31</description>
  <thedate>2013-01-17T00:00:00</thedate>
  <somenotes> </somenotes>
</row>
<row>
  <id>10</id>
  <description>description 41</description>
  <thedate>2013-01-11T00:00:00</thedate>
  <somenotes> </somenotes>
</row>
<row>
  <id>11</id>
  <description>description 51</description>
  <thedate>2013-06-03T00:00:00</thedate>
  <somenotes> </somenotes>
</row>
<row>
  <id>12</id>
  <description>description 61</description>
  <thedate>2013-06-01T00:00:00</thedate>
  <somenotes>some other notes</somenotes>
</row>
<row>
  <id>13</id>
  <description>desc 55</description>
  <thedate>2013-06-25T00:00:00</thedate>
  <somenotes>aSAdaD
D
Ad
aDa</somenotes>
</row>
<row>
  <id>14</id>
  <description>desc 99</description>
  <thedate>2013-06-24T00:00:00</thedate>
</row>
<row>
  <id>15</id>
  <description>desk 888</description>
  <thedate>2013-05-10T00:00:00</thedate>
</row>
<row>
  <id>16</id>
  <description>test again</description>
  <thedate>2013-05-02T00:00:00</thedate>
  <somenotes>'ad</somenotes>
</row>
</data>

我用dataGridView和testBox创建了一个简单的windows窗体应用程序。以下是我想做的:

  1. 我只想将"id"、"description"answers"thedate"元素作为列加载到dataGridView中,然后在dataGridView 中单击相应的单元格时,在testBox中显示"somenotes"

  2. 我还希望能够使用"thedate"元素过滤dataGridView,这样我就可以使用表单上的按钮在今天、本周、本月、今年之前进行过滤。

如果有任何帮助,我将不胜感激,因为我在使用c#的XML文件方面非常缺乏经验。我想用最简单的方式来做这件事,所以没有什么是非常复杂的,再次感谢。

C#-将XML文件的特定元素读取到dataGridView中,并在文本框中显示其余部分

1.将xml读取到dataTable。

2.将dataGridView的数据源绑定到dataTable。

3.在dataGridView中设置列的显示。