将MatchCollection插入datagridview c#

将MatchCollection插入datagridview c#,c#,winforms,datagrid,datagridview,C#,Winforms,Datagrid,Datagridview,我有一个datagridview,它有两列和一个MatchCollection,我将使用它来填充datagrid。如何在datagrid中为第一列插入matchcollection中的第一个匹配项,然后为第二列插入matchcollection的第二个值。然后它将创建一个新行并重新开始 没有数据绑定到此gridview,我需要确保插入datagrid的matchCollection不会覆盖表中的任何其他内容。我该怎么做 这是在窗体应用程序而不是asp.net中完成的 while (!sr.En

我有一个datagridview,它有两列和一个MatchCollection,我将使用它来填充datagrid。如何在datagrid中为第一列插入matchcollection中的第一个匹配项,然后为第二列插入matchcollection的第二个值。然后它将创建一个新行并重新开始

没有数据绑定到此gridview,我需要确保插入datagrid的matchCollection不会覆盖表中的任何其他内容。我该怎么做

这是在窗体应用程序而不是asp.net中完成的

 while (!sr.EndOfStream)
                    {
                        string line = sr.ReadLine();
                        line = line.Trim();
                        if (line.StartsWith("addTestingPageContentText"))
                        {
                            string temp;
                            string pattern = "\"([^\"]+)\"";
                            Regex r = new Regex(pattern);
                            MatchCollection regs = r.Matches(line);

                            foreach (Match reg in regs)
                            {

                                temp = reg.ToString();
                                temp = temp.Replace("\"", "");

                               int rowCount = contentTable_grd.Rows.Count - 1;


                        if (contentTable_grd.Rows[rowCount].Cells[0].Value == null)
                            contentTable_grd.Rows[rowCount].Cells[0].Value = temp;
                        else
                            contentTable_grd.Rows[rowCount].Cells[1].Value = temp;


                        contentTable_grd.Rows.Add();

                            }
                        }
                    }         

您可以创建自定义gridview列并从DataGridViewTextBoxCell继承

试试这个

while (!sr.EndOfStream)
            {
                string line = sr.ReadLine();
                line = line.Trim();
                if (line.StartsWith("addTestingPageContentText"))
                {
                    string temp;
                    string pattern = "\"([^\"]+)\"";
                    Regex r = new Regex(pattern);
                    MatchCollection regs = r.Matches(line);


                    object[] array1 = new object[2];                    



                    foreach (Match reg in regs)
                    {

                        temp = reg.ToString();
                        temp = temp.Replace("\"", "");

                        if (array1[0] == null)
                            array1[0] = temp;
                        else
                            array1[1] = temp;
                    }

                    if (regs.Count > 0)
                        contentTable_grd.Rows.Add(array1);
                }
            }