This is a migrated thread and some comments may be shown as answers.

Updating Bound Column Readonly Issue

1 Answer 54 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Guru
Top achievements
Rank 2
Guru asked on 11 Sep 2012, 10:15 PM
We have a gridview.ItemSource = datafilter.FilterdSource and the datafilter.Source = datatable.DefaultView. When we (manually) generate the columns they are type of GridViewColumnBase and the columns to be updated are of DataType System.String. The gridview is set to readonly and we set some values in the background depending on user actions. Generally the action is based on a context menu click and we are accessing the record as (gridview.Items[i] as DataRowView). We then set the value of the cell by the column name and it works great but sometimes it will give us an exception saying the column 'x' is readonly... can't figure our why.

Routine to update is similar to the following:
string c = "ColumnUniqueName", v = "ValueToSet";
DataRowView r = (gridview.Items[i] as DataRowView);
r[c] = v; //her we get the error

Error:
Message: Column 'ColumnUniqueName' is read only.

Source: System.Data

Trace:    at System.Data.DataRow.set_Item(DataColumn column, Object value)
   at System.Data.DataRowView.SetColumnValue(DataColumn column, Object value)
   at System.Data.DataRowView.set_Item(String property, Object value)


1 Answer, 1 is accepted

Sort by
0
Guru
Top achievements
Rank 2
answered on 13 Sep 2012, 04:09 PM
After a little head scratching I figured out setting each columns readonly property when creating the actual datatable itself solves the issue.
Tags
GridView
Asked by
Guru
Top achievements
Rank 2
Answers by
Guru
Top achievements
Rank 2
Share this question
or