Update datatable by code

L

Lars E.

Hei,
In my vb.net winapp I have a datagrid that uses a datatable
(dtGridReport) as datasource.
When I try to update one field in my datatable something strange
happens.
It looks as if a row is added to the datagrid, a new row appears,
which is a copy of the row I wanted to update.
The datatable still contains the correct number of rows.

An example of code to change the data which causes the problem to
occur:
Dim dr As DataRow() = dtGridReport.Select("sFkAccountID = '0301'")
If dr.GetUpperBound(0) = 0 Then
dr(0)("sValue") = "whatever"
End If

Does anybody know why this happens or what I can do to fix it?
 
L

Lars E.

I've found out it only happens when I have added rows to the datatable
using InsertAt()
 
L

Lars E.

A new row would appear if I called InsertAt.
:)

But that's not the point here.
I insert the rows using InsertAt before I bind the table to the grid.
When I later try to update a row via code a new copy of that row shows
up in the grid.

I think I have found a dirty way to go around it, but I don't like it
when stuff happens that I can't explain.
 

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