1

データグリッドに入力したい整形式の XML ファイルがあります。WFPToolKit データグリッドの AutoGenerate 機能を使用することをお勧めしますが、列をハードコーディングできます。

私が抱えている問題は、xml ファイルの内容をデータグリッドに取得することです。リストビューで部分的に機能していましたが、データグリッドの方が私のニーズにより適していると思います。

これを達成する方法の簡単な例を誰かが提供できますか?

4

2 に答える 2

1

あはは!ここで別の投稿の助けを借りて、最終的に解決しました。以下は、各 XML 要素をリスト ビューに追加して、作業を行うことができたものです。

XDocument xdoc = XDocument.Load("c:\\isbn.xml");
var items = from item in xdoc.Descendants("BookData")
            select new
            {
                Title = item.Element("Title").Value,
                AuthTexts = item.Element("AuthorsText").Value
            };

foreach (var item in items)
{
    listView1.Items.Add(new { Title = item.Title, Author = item.AuthTexts });
}
于 2009-09-06T02:54:36.130 に答える
1

次のように、XML を ListView にバインドします。

// Bind the data to the ListView
var binding = new System.Windows.Data.Binding() {  
  Source = MergedXmlDataProvider,  
  UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged,  
  XPath = "//element" };  
this.listView1.SetBinding(ItemsControl.ItemsSourceProperty, binding);   

XML は次のようになります。

<root>  
    <element location="here" state="now"/>  
    <element location="there" state="then"/>  
</root> 
于 2009-09-08T21:47:15.700 に答える