linq to xml 我需要做什么才能绑定到 gridview?

发布于 2024-12-04 05:43:06 字数 3116 浏览 1 评论 0原文

如何设置 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");
                                }

                            }
                        }
                    }

                }

            }
        }
    }
}

How do I setup VSTUDIO in order to bind my linq to xml query results to gridview rather than writing to console?

namespace TestCFG

{
class Program
{
public class 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");
                                }

                            }
                        }
                    }

                }

            }
        }
    }
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

慈悲佛祖 2024-12-11 05:43:06

您可以简单地执行一些操作,例如

YourDataGrid.DataSource = query3.ToList();

YourDataGrid 是一个虚构的对象,应将其替换为您在 Windows 窗体应用程序或 WPF 应用程序中创建的 DataGrid 的任何名称(尽管这更复杂)

You can simply do something such as

YourDataGrid.DataSource = query3.ToList();

YourDataGrid is a fictitious object that should be replaced with whatever name you give the DataGrid that you create in a Windows Form application or a WPF application (though this is more complex)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文