如何在C#中使用datagridview创建和填充第二列? [英] How to create and fill in the second column using datagridview in C#?

查看:110
本文介绍了如何在C#中使用datagridview创建和填充第二列?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好



我想创建两列并从一个html文件中获取一些信息。我可以创建第一列,然后填写行。我创建了第二列,但我无法填写第二列的行?请你帮助我好吗?



问候



我的尝试:



Hello

I would like to create two columns and take some information from one html file. I can create the first column and I filled in the rows. I created the second column but I can't fill in the rows of the second column? Could you please help me?

Regards

What I have tried:

string inner = doc.DocumentNode.SelectSingleNode("//a[@ class='a-link-normal s-access-detail-page  s-color-twister-title-link a-text-normal']").InnerText;
            var nodes = doc.DocumentNode.SelectNodes("//span[@ class='a-offscreen']");
            string[] s = new string[20];
            string[] ss = new string[20];
            string[] s1 = new string[500];
            string[] ss1 = new string[500];
            dataGridView2.ColumnCount = 2;
            dataGridView2.Columns[0].Name = "Price";
            dataGridView2.Columns[1].Name = "Name";

            dataGridView2.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill;
            foreach(HtmlAgilityPack.HtmlNode item in nodes)
            {
                s[0] = item.InnerText;
       
                ss = (string[])s.ToArray();
                dataGridView2.Rows.Add(ss[0]);
                
                dataGridView2.Rows.Add(ss[0]);              

            }

推荐答案

您所要做的就是调试代码。

看看你的代码 - 原因似乎很明显(参见我的评论):

All you have to do is to debug your code.
Take a look at your code - a reason seems to be quite obvious (see my comments):
foreach(HtmlAgilityPack.HtmlNode item in nodes)
{
    s[0] = item.InnerText;  
    ss = (string[])s.ToArray(); //unused variable
    dataGridView2.Rows.Add(ss[0]); //same as below
    dataGridView2.Rows.Add(ss[0]); //same as above              
}


这篇关于如何在C#中使用datagridview创建和填充第二列?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆