我花了大约三周的时间试图找到这方面的信息,但没有成功。 与编辑相关的DGV设置: readonly 在 DGV 上为 false 编辑模式是 DGV 上的按键。
代码在这里: http://pastebin.com/eCv3iBcF
但是,当尝试编辑时,没有任何反应,框只是从选择中变成颜色;鼠标不会改变以识别文本,击键不起作用。
这应该做什么(至少在我的脑海中并且根据图): 叫表。 填充 DGV。 允许通过按键编辑选定的字段。
最佳答案
问题在于您将 BindingSource 对象的数据源设置为 SQLDataReader 对象。这是一个只读对象。
A DataReader is limited to being read-only and forward-only. That is, the information retrieved from the database cannot be modified by the DataReader, nor can the DataReader retrieve records in a random order. Instead, a DataReader is limited to accessing the records in sequential order, from the first one to the last one, one record at a time."
您应该使用 DataAdpater 并填充 DataTable。
然后,您可以使用 DataTable 作为 BindingSource 的数据源。
或者,您可以像这样勾选 DataReader:-
using(SqlDataReader reader = command.ExecuteReader())
{
DataTable data = new DataTable();
data.Load(reader);
}
希望这有帮助。
关于c# - Visual C# DataGridView 编辑;已设置所有可能的编辑选项;不会编辑,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15908202/