sharkyenergy sharkyenergy - 11 months ago 93 Question

edit content of cell programmatically in bound datagridview

I would need to edit the content of a bound and filtered datagridview programmatically.

I tried following, but did not work:

DataGridView1.Rows(rcly).Cells(33).Value = "False"

I cannot edit de bound data table since the datagridview is filtered and I do not know at what location inside the dataset the value is that i have to edit, so I would like to edit it programmatically inside the datagridview and use the bindig to mirror the change in the data table in order to be able to use the filter funcion.


Answer Source

DataGridViewRow has an attribute called DataBoundItem. You can access a DataRowView which has a ReadOnly attribute called Row which is the DataRow you want to edit.

I don't know if you can edit attributes of the DataRow since its ReadOnly. If you can't edit it then you will have to access the Row by using

 Dim TheRow as DataRow
 TheRow = DataGridView1.Rows(rcly).DataBoundItem.Row

To edit values in the DataRow use

TheRow.Item("ColumnName") = "Your new Value"

You can also access the Item by Index, but I would highly recommend using the name.