c# - Visual C# DataGridView 编辑;已设置所有可能的编辑选项;不会编辑

标签 c# mysql datagridview phpmyadmin

我花了大约三周的时间试图找到这方面的信息,但没有成功。 与编辑相关的DGV设置: readonly 在 DGV 上为 false 编辑模式是 DGV 上的按键。

代码在这里: http://pastebin.com/eCv3iBcF

但是,当尝试编辑时,没有任何反应,框只是从选择中变成颜色;鼠标不会改变以识别文本,击键不起作用。

这应该做什么(至少在我的脑海中并且根据图): 叫表。 填充 DGV。 允许通过按键编辑选定的字段。

最佳答案

问题在于您将 Bi​​ndingSource 对象的数据源设置为 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/

相关文章:

vb.net - 问题检测 DataGridView 中的复选框状态

c# - DataGridView 使用 ComboBox 绑定(bind)到 DataTable

c# - 如何在按下 tab 键时跳过 datagridview 中的列

c# - C#静态类需要实例化吗?

c# - Signalr 在生产服务器中总是陷入长轮询

mysql - 在mysql中俱乐部两个查询

mysql - Jmeter只能测量操作系统级别的指标吗?

c# - Linq 连接两个值

c# - 将用户文本框输入(数字)放入定义的数组大小并输出?

mysql加入csv字段?