2013-07-10 41 views
0

嗨,我遇到了一個我希望得到一些幫助的問題。首先我在這裏C# - 將XML文件的特定元素讀入dataGridView並在文本框中顯示其餘部分

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

有一個XML文件,我已經創建了一個DataGridView和TESTBOX一個簡單的Windows窗體應用程序。這裏是我想要做什麼:

  1. 我只想加載「ID」,「描述」和「thedate」元素到DataGridView的列,然後有「somenotes」出現在testBox當相應的單元格在dataGridView中點擊時

  2. 我還希望能夠使用「thedate」元素過濾dataGridView,這樣我就可以在今年本週這個月過濾使用按鈕在窗體上。

任何與此有關的幫助將不勝感激,因爲我對c#使用XML文件的經驗不足。我想以最簡單的方式做到這一點,所以沒有什麼必須非常複雜,再次感謝。

+1

使用linq到XML http://stackoverflow.com/questions/4023090/linq-to-xml-and-datagridview – MEYWD

回答

0

1.讀取xml到dataTable。

2.將dataGridView的數據源綁定到dataTable。

3.在dataGridView中設置coloumn的顯示。

相關問題