Missing datarow

timh

Well-known member
Joined
Nov 28, 2008
Messages
50
Programming Experience
Beginner
Hello,

I am writing some code to import data in a .csv file to a dataview, which is displayed in a datagridview and thereby to the underlying data source.

I can import to the dgv fine, but when I close the form containing the dgv, the last row of the new data gets lost?? I have no idea why this is happening, but perhaps someone can spot an obvious flaw in my code.

What happens is that I have an in memory data table containing my new data (newdataDT), which is then mapped to columns in elistdataview, based on values in an list which I've called "maprows". The mapping happens fine and the new data appears in the dgv OK. Just that when I close the form, the underlying datatable that elistdataview is bound to loses the last row of data.

VB.NET:
        With elistdataview
            origcount = .Count
            Try
                lasturn = .Item(.Count - 1).Item("urn")
            Catch ex As Exception
                lasturn = 0
            End Try
            newurn = lasturn + 1
            For Each row As DataRow In newdataDT.Rows
                temprow = .AddNew()
                temprow.Item("urn") = newurn
                For i = 0 To maprows.Count - 1
                    map = Split(maprows.Item(i), ",")
                    Try
                        temprow.Item(map(2)) = row.Item(map(0)).ToString
                    Catch ex As System.Data.DataException
                        'do nothing and skip to next field
                    Catch ex As Exception
                        MessageBox.Show(ex.ToString)
                        Exit Sub
                    End Try
                Next
                newurn += 1
            Next
            DataGridView1.Rows(origcount).Selected = True
        End With

Any help please?

Thanks.
 
Ah, simple then. I guess the other rows work because the add new method effectively calls end edit on the previous row. So simple. Been scratching my head for a while...

Thank you very much once again.
 
Back
Top