1

これまで、アプリケーションにデータを保存するためにテキストファイルを使用してきました。それらは一種のコンマ区切りです。ListViewとかなりの数のコードを使用して、データを表示しました。

今日、私はDataSetコンポーネントとDataGridコンポーネントについて知りました。使ってみたいです。その後、私のデータをXMLに保存できます。これは、サーバーもそれを行うので便利です。

しかし、それを機能させる方法がわかりません。私は単純な階層を持っています:

<myapp>
  <user>
    <firstname>John</firstname>
    <lastname>Doe</lastname>
  </user>
  <collection>
    <name>Beer cans</name>
    <item>
      <id>1</id>
      <name>Heineken</name>
    </item>
  </collection>
  <collection>
    <name>Coffee mugs</name>
    <item>
      <id>18</id>
      <name>Starbucks</name>
    </item>
  </collection>
</myapp>

通常、コレクション要素を親要素でラップしますが、VB.NETでは複雑になるようです。いずれかの方法。私の質問は...

ユーザーがクリックできるコレクションのリストがアプリにある場合は、そのコレクション内のすべてのアイテムをDataGridに表示したいと思います。

これまでの私のコードは適切なコレクションをいくらか選択していますが、たとえばアイテム自体に到達できないようです。

Dim DataSet As New DataSet
DataSet.ReadXml("c:\john.doe.xml")
MainGrid.DataSource = DataSet.Tables("collection").Select("name='" & selName & "'")

(編集:タイプミス)

4

2 に答える 2

1
    If NetworkInterface.GetIsNetworkAvailable Then
        Dim cl As New WebClient
        AddHandler cl.DownloadStringCompleted, AddressOf cl_DownloadStringCompleted
        Dim url As String = "Your link in here"
        cl.DownloadStringAsync(New Uri(url))
    Else
        MessageBox.Show("check your internet connection first")
    End If

Private Sub cl_DownloadStringCompleted(sender As Object, e As System.Net.DownloadStringCompletedEventArgs)
Dim doc = XDocument.Parse(e.Result)
For Each result In doc.<myapp>.<user>
        TextBlock1.Text = TextBlock1.Text & Environment.NewLine & result.<firstname>.Value
    Next
End Sub

私はそれがうまくいくことを願っています:)

于 2013-02-03T21:56:58.963 に答える
0

これを試して :

Dim CollectionTable As DataTable = DataSet.Tables("collection")
Dim CollectionSelection As DataRow() = CollectionTable.Select("name='" & selName & "'")
Dim CollectionID As Integer

If CollectionSelection.Count = 1 Then
    CollectionID = CollectionSelection(0)("collection_id")
Else
    Exit Sub
End If

MainGrid.DataSource = DataSet.Tables("item").Select("collection_id =" & CollectionID).CopyToDataTable()

DataSet は xml を読み取り、3 つのテーブル と を作成してusercollectionますitemitem表には 3 つの列がありますid name collection_id。そのため、コレクション名に基づいて collection_id を選択し、その id に基づいてアイテムを選択しました。コレクション テーブルには列nameとがあることに注意してくださいcollection_id

于 2013-02-02T16:36:45.410 に答える