datagrid bound to dataview nullreferenceexception in paint after adding row

A

Alberta Smith

I have two tables and a parent-child relationship between them. On the
child table i created a calculated field that goes to the parent table
to get a value (child table has a code and parent table has a
description for that code:Expresion=parent(myrelation).mydescfield). I
have a form showing a parent-datatable row and a datagrid bound to the
relation showing related child rows. I use a DataViewManager as
datasource to sort data.

I create programatically a new row (using currencymanager.addnew(),
currencymanager.endcurrentedit() of the relation) in the child table
and the datagrid shows it correctly. Then i modify a field in that new
row on the datagrid. Then i move to another row in the datagrid and it
explodes:

Excepción no controlada: System.NullReferenceException: Referencia a
objeto no establecida como instancia de un objeto.
at System.Data.DataView.IsOriginalVersion(Int32 index)
at System.Data.DataRowView.GetColumnValue(DataColumn column)
at System.Data.DataColumnPropertyDescriptor.GetValue(Object
component)
at System.Windows.Forms.DataGridColumnStyle.GetColumnValueAtRow(CurrencyManager
source, Int32 rowNum)
at System.Windows.Forms.DataGridTextBoxColumn.Paint(Graphics g,
Rectangle bounds, CurrencyManager source, Int32 rowNum, Brush
backBrush, Brush foreBrush,
...


If i remove the calculated field from the child table and everything
works ok. But i need to show this calculated field in the grid so i
can't just remove it. And also, if i use the dataset as datasource
instead of the dataviewmanager everythinks works (except the tables
doesn't show ordered first time).

I am frustrated. Any hint?
 
A

Alberta Smith

I found the cause of this error, but i think it is a bug.

I was binding a datagrid with a dataview obtained from a
dataviewmanager. The dataview corresponds to a table that has a
calculated field (in the form of parent(relation).field). The
dataviewmanager default sorting for the source table for this dataview
was the calculated field.

If i change the default ordering for that table in the dataviewmanager
everything works ok.

I think databinding in .net has too much bugs to truly be a
professional solution for data driven applications.
 

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