Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/329.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/.net/25.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 将值从Windows注册表传输到DataGridView表_C#_.net_Windows_Registry - Fatal编程技术网

C# 将值从Windows注册表传输到DataGridView表

C# 将值从Windows注册表传输到DataGridView表,c#,.net,windows,registry,C#,.net,Windows,Registry,我有一个应用程序,它的主窗体上有一个DataGridView。应用程序的一个功能是从DataGridView读取和写入注册表。我能够写入注册表,目前正在尝试从注册表读取,但在将最终值放入表中时遇到问题 foreach (var x in Test.GetSubKeyNames()) { RegistryKey product = Test.OpenSubKey(x); //string SubKey = Convert.ToStri

我有一个应用程序,它的主窗体上有一个
DataGridView
。应用程序的一个功能是从
DataGridView
读取和写入注册表。我能够写入注册表,目前正在尝试从注册表读取,但在将最终值放入表中时遇到问题

foreach (var x in Test.GetSubKeyNames())
        {
            RegistryKey product = Test.OpenSubKey(x);
            //string SubKey = Convert.ToString(product);

            Console.WriteLine("+\tKey: " + product);

            //Testing
            foreach (var value in product.GetValueNames())
            {
                Console.WriteLine("+\tValue: " + value);
                string keyValue = Convert.ToString(product.GetValue(value));

                //Having trouble here 
                StudentGridView.CurrentRow.Cells["Age"].Value = keyValue;

            }

        }

        Console.ReadLine();
申请表有三栏——姓名、年龄、学校。注册表中有一个名为“Students”的子项,该子项中有几个学生姓名,这些姓名的年龄和学校值不同。我想获取子键名称并将其传输到
DataGridView
中的Name列,然后获取年龄和学校值并将其传输到表中的相应列

foreach (var x in Test.GetSubKeyNames())
        {
            RegistryKey product = Test.OpenSubKey(x);
            //string SubKey = Convert.ToString(product);

            Console.WriteLine("+\tKey: " + product);

            //Testing
            foreach (var value in product.GetValueNames())
            {
                Console.WriteLine("+\tValue: " + value);
                string keyValue = Convert.ToString(product.GetValue(value));

                //Having trouble here 
                StudentGridView.CurrentRow.Cells["Age"].Value = keyValue;

            }

        }

        Console.ReadLine();

您好,您可以将dataGridView绑定到注册表,而无需编写此循环,但您必须将子项转换为列表或数组,我不知道dataGridView是否接受子项。啊,我不知道您可以这么做-我如何绑定它@mehdizahraneTo要进行这样的绑定,您需要给它一个数据源,例如,一个学生列表,“list list list”,将datagridview与列表GridView1.datasource=list绑定;GridView1.DataBind();