简体   繁体   English

无法编辑 C# 中的 DataGridView 单元格

[英]Can't edit DataGridView cell in C#

I have a datagridview in Windows Forms C# application.我在 Windows Forms C# 应用程序中有一个 datagridview。 It's datasource is DataSet, which has TableAdapter in it.它的数据源是DataSet,里面有TableAdapter。 The SQL method that gets the results has a couple INNER JOINs in it.获取结果的 SQL 方法中有几个 INNER JOIN。 The data is shown in the gridview, but I have a field there that I want to update.数据显示在 gridview 中,但我有一个要更新的字段。 But, it's readonly in the gridview.但是,它在 gridview 中是只读的。 The readonly value to that cell is set to false.该单元格的只读值设置为 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.我在某处读到我的数据源不可更新,这就是 gridview 控件不允许我更新它的原因。 But I have to update it.但我必须更新它。 Do you have any solution to this?你有什么解决办法吗?

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.这可能是由于使用带有连接的 TableAdapter - TableAdapter 向导在使用连接时无法自动生成插入、更新和删除命令。

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).您可以通过在数据集设计器中查看 TableAdapter 的属性来验证是否是这种情况 - 命令将显示(无)。

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这是将这些命令添加到 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.就个人而言,我更喜欢使用自定义数据访问层,完全取消 TableAdapter 及其自动生成的代码。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM