Exception while using DataRowView

D

Dave Cotton

Howdy,
I'm using a DataRowView that I create via a
BindingContext from a DataGrid. The problem is that
sometimes I get an exception that says Cannot Set 'column
name'. I'm wondering if anyone is familiar with this
message and under what conditions it might occur. And of
course, a way around the problem.

I'm using C# 7.0.9466, I've updated the framework to 1.1.
Also, this is not a web app. Currently the code looks
like this:
BindingManagerBase BMB = BindingContext
[dataGrid1.DataSource, dataGrid1.DataMember];
PropertyDescriptorCollection pc = BMB.GetItemProperties();
BMB.Position = (int)dataGrid1.SelList[0];
DataRowView drv = (DataRowView)BMB.Current;

I've also tried:
DataRowView drv = (DataRowView)BindingContext
[dataGrid1.DataSource, dataGrid1.DataMember].Current;

The SelList property is something I added that keeps
track of which rows are currently selected. It's
primarily used to do a multi-row update. However, since
the multi-update works and the single update doesn't.
I've been trying to make the single update more like the
multi-update. Thus, the reason for the change from the
simple BindingContext that I noted I tried.

The actual exception occurs on this statement:
drv["Name"] = str;
When I try to set the value of the field. I've looked at
the properties just before the read and ReadOnly is
false. I can read from the field. I just cannot, for some
reason, set the field value.
I've also checked drv.DataView.AllowEdit this value is
also true. Interestingly,
drv.Row.ItemArray[3] = "Value";
does not give an exception.


Thanks,
Dave
 
K

Kathleen Dollard

Dave,

Does this happen always with particular columns, or occasionally with random
columns?

I'd look about six different times for a spelling error.
 
D

Dave Cotton

Happens every time with every field. And, ya, I've copied
and pasted field names, I've had multiple people look to
make sure I haven't mispelled the field name. Also, as
part of my current work around, I created a function that
I pass in the name and the table, it scans the list of
columns and returns an index. This function finds the
field names just fine.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top