Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can't edit DataGridView content (even when ReadOnly = false) when clicking on it?

The context here is I use a special kind of DataSource for DataGridView, that is an anonymous type which can be created as follow:

var data = new[] { new { A = "A", B = 1 }, new { A = "B", B = 2 }, new { A = "C", B = 3 }};

The problem is if I use the above data source for a DataGridView, I can't edit the content of the DataGridView starting by clicking on its cells.

myDataGridView.DataSource = data;

Could you please explain to me why and how to make it editable? Or simply we can't make it work that way?

Your help would be highly appreciated.

like image 473
King King Avatar asked Jan 18 '26 18:01

King King


2 Answers

Its because var data is anonymous type. And anonymous type properties are read-only.

like image 61
Aseem Gautam Avatar answered Jan 20 '26 08:01

Aseem Gautam


I am not 100% sure about this but I think that you can't edit the grid because you are binding an anonymous type. Anonymous types cannot be changed.

like image 31
Flavia Avatar answered Jan 20 '26 08:01

Flavia



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!