【发布时间】:2014-06-12 20:58:15
【问题描述】:
我有 datagridview 来显示一些数据。
我用:
dataGridView1.SelectionMode = DataGridViewSelectionMode.FullRowSelect;
选择整列。
当我运行应用程序 datagridview 时自动选择第一列。我正在尝试禁用它。
如果我添加:
dataGridView1.ClearSelection();
什么都没有发生。
如果我添加:
dataGridView1.Columns[-1].Selected = true;
如果在 Virtual Studio 中构建效果很好,但是在没有 Virtual Studio 的情况下构建时会出错:
Index was out of range. Must be non-negative and less than the size of the collection. Parameter name:index
如果我点击继续,它可以工作,但错误很烦人。
我试过了:
dataGridView1.SelectedColumns.Clear();
使用 Virtual Studio 构建时效果很好,但是在没有 Virtual Studio 的情况下构建时出现错误提示:
Collection is read-only.
这个错误也很烦人。
我认为最好的解决方案是将集合设置为非只读。但我不知道该怎么做。
任何简单的解决方案都会很棒!谢谢!
【问题讨论】:
标签: c# collections datagridview readonly