2011-09-12 4 views
0

コンソールに書き込むのではなく、linqをxmlクエリ結果にバインドするためにVSTUDIOを設定するにはどうすればよいですか?linq to xml gridviewにバインドするには何が必要ですか?

namespace TestCFG 

{ クラスプログラム { パブリッククラスXAxisCalib {

 static void Main(string[] args) 
     { 
      { 


       string[] fileEntries = Directory.GetFiles(@"c:\Sciclone UAC", "*.cfg*"); 
       foreach (string fileName in fileEntries) 
       { 
        XDocument doc = XDocument.Load(fileName); 
        var query = from x in doc.Descendants("XAxisCalib") 
           select new 
           { 

            MaxChild = x.Descendants("Max"), 
            MinChild = x.Descendants("Min") 
           }; 
        foreach (var x in query) 
        { 
         foreach (var nextLevel in x.MaxChild) 
         { 
          Console.WriteLine("" + nextLevel.Value); 
         } 
         foreach (var nextLevel in x.MinChild) 
         { 
          Console.WriteLine("" + nextLevel.Value + "\n"); 
         } 



         var query2 = from y in doc.Descendants("YAxisCalib") 

            select new 
            { 

             MaxChild = y.Descendants("Max"), 
             MinChild = y.Descendants("Min") 

            }; 


         foreach (var y in query2) 
         { 
          foreach (var nextLevel in y.MaxChild) 
          { 
           Console.WriteLine("" + nextLevel.Value); 
          } 
          foreach (var nextLevel in y.MinChild) 
          { 
           Console.WriteLine("" + nextLevel.Value + "\n"); 
          } 

          var query3 = from z in doc.Descendants("ZAxisCalib") 

             select new 
             { 

              MaxChild = z.Descendants("Max"), 
              MinChild = z.Descendants("Min") 
             }; 

          foreach (var z in query3) 
          { 
           foreach (var nextLevel in z.MaxChild) 
           { 
            Console.WriteLine("" + nextLevel.Value); 
           } 
           foreach (var nextLevel in z.MinChild) 
           { 
            Console.WriteLine("" + nextLevel.Value + "\n"); 
           } 

          } 
         } 
        } 

       } 

      } 
     } 
    } 
} 

答えて

0

あなたは単に

YourDataGrid.DataSource = query3.ToList(); 

YourDataGridような何かを行うことができますが置き換えてください架空のオブジェクトがありますWindowsフォームアプリケーションで作成したDataGridに与える名前アプリケーションやWPFアプリケーション(より複雑ですが)

+0

私はコンソールアプリケーションを使用していますか?エラー:YourDataGridが現在のコンテキストに存在しません。 –

+1

@Casey no、WinFormsまたはWPFアプリケーションを作成し、メインウィンドウにDataGridを追加する必要があります。新しいプロジェクト - WinFormsまたはWPF - を作成するだけで、ツールボックスからグリッドビュー(他のコンポーネントと同様)をドラッグできる空白のウィンドウが表示されます。 –

関連する問題