【发布时间】:2015-04-09 23:21:07
【问题描述】:
我的表单在选项卡控件的不同选项卡中有 6 个 dataGridViews,用户可以输入值并更改单元格背景颜色,使用保存按钮,每个 dataGridView 的值都保存到文本文件中,与背景颜色相同每个 dataGridView 中的单元格。当用户重新打开表单时,所有最后的设置(样式和值)再次加载到 6 个 dataGridViews;问题是当用户重新打开表单时,dataGridViews 冻结,我找不到解决方法。有人可以帮我吗?
我的加载数据和样式代码:
foreach (string s in File.ReadAllLines(stylePath))
{
string[] items = s.Split(';');
if (items.Length == 3)
{
dataGridView1.Rows[Convert.ToInt32(items[0])]
.Cells[Convert.ToInt32(items[1])]
.Style.BackColor = Color.FromName(Convert.ToString(items[2]));
}
}
StreamReader sr = new StreamReader(valuePath);
foreach (DataGridViewRow row in dataGridView1.Rows)
{
foreach (DataGridViewCell cell in row.Cells)
{
cell.Value = sr.ReadLine();
}
}
sr.Close();
以下是重新打开表单时的外观:
【问题讨论】:
-
克里斯:我们需要查看一些代码来了解它在哪里冻结
-
请编辑/添加您重新打开的部分,从文件中读取,更新gridViews
-
@chouaib 我注意到了更多,如果我不运行 LoadStyle void,那么 dataGridView 没有冻结。
标签: c# winforms datagridview styles freeze