Can't edit DataGridView cell in C#
I have a datagridview in Windows Forms C# application. It's datasource is DataS开发者_开发知识库et, 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?
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.
精彩评论