【发布时间】:2011-10-17 22:40:50
【问题描述】:
我有一个数据网格视图,它有 2 列和一个 MatchCollection,我将使用它来填充数据网格。如何在第一列的数据网格中插入 matchcollection 中的第一个匹配项,然后为第二列插入 matchcollection 的第二个值。然后它将创建一个新行并重新开始。
没有数据绑定到此网格视图,我需要确保插入数据网格的 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();
}
}
}
【问题讨论】:
标签: c# winforms datagrid datagridview