DataRowView Cannot Set 'Column' exception

D

Dave Cotton

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.

Thanks,
Dave
 
M

Miha Markic

Hi Dave,

I am not sure I understand how you create your DataRowView.
Can you show us a snippet of code?
When do you get an exception?
 
G

Guest

Sure, BTW, 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;
UpdateDB (drv);

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.
 
G

Guest

I have a 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.
 
M

Miha Markic

Hi,

What does drv.DataView.AllowEdit say?

--
Miha Markic - RightHand .NET consulting & software development
miha at rthand com
www.rthand.com

I have a 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.
-----Original Message-----
Hi,

And where do you get the exception?
 
G

Guest

It's value is true. Currently, I'm trying to get around
the problem like this:
drv.Row.ItemArray[3] = 'Value';
 
Joined
Jul 22, 2014
Messages
1
Reaction score
0
I am having the same issue.
I created a view on a dataTable and I want to set the value of a column
so:
DataRowView dr = myDataView[rownum];

dr["myBool"] = false;

I get a "Cannot set myBool" error.
My dataView is set to allow edits.
It doesn't provide any more info.
Has anyone run into this before?
Am I doing something wrong?
 

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