无法在 C# 中编辑 DataGridView 单元格
我在 Windows 窗体 C# 应用程序中有一个 datagridview。它的数据源是DataSet,其中有TableAdapter。获取结果的 SQL 方法中有几个 INNER JOIN。数据显示在网格视图中,但我有一个想要更新的字段。但是,它在网格视图中是只读的。该单元格的只读值设置为 false。我在某处读到我的数据源不可更新,这就是 gridview 控件不允许我更新它的原因。但我必须更新它。你对此有什么解决办法吗?
I have a datagridview in Windows Forms C# application. It's datasource is DataSet, which has TableAdapter in it. The SQL method that gets the results has a couple INNER JOINs in it. The data is shown in the gridview, but I have a field there that I want to update. But, it's readonly in the gridview. The readonly value to that cell is set to false. I've read somewhere that my datasource is not updatable and that is the reason why the gridview control is not letting me to update it. But I have to update it. Do you have any solution to this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这可能是由于使用带有联接的 TableAdapter - TableAdapter 向导在使用联接时无法自动生成插入、更新和删除命令。
您可以通过查看数据集设计器中 TableAdapter 的属性来验证是否属于这种情况 - 命令将显示(无)。
以下是有关将这些命令添加到 TableAdapter 的教程: http://www.asp.net/data-access/tutorials/updating-the-tableadapter-to-use-joins-vb
就我个人而言,我更喜欢使用自定义数据访问层,从而消除TableAdapter 及其自动生成的代码完全。
This is probably due to using the TableAdapter with joins - the TableAdapter wizard is not able to automatically generate the Insert, Update and Delete commands when using joins.
You can verify if this is the case by looking at the properties of the TableAdapter in the dataset designer - the commands will show (None).
Here is a tutorial on adding these commands to a TableAdapter: http://www.asp.net/data-access/tutorials/updating-the-tableadapter-to-use-joins-vb
Personally, I prefer to use a custom dataaccess layer, doing away with the TableAdapter and its autogenerated code entirely.