For Programmers: Free Programming Magazines  


Home > Archive > VB Controls Databound > January 2005 > Has anyone gotten InsertAt to work ?









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Has anyone gotten InsertAt to work ?
Peter Sandstrom

2005-01-23, 9:01 pm

Hi,

I wonder if anyone has been able to get the DataRowCollection.InsertAt
method to work correctly? I use .NET 1.1.4322 SP1 on win XP. The data
resides in a xml-file, it consists of 5 items (companies) which is read into
a dataset and displayed in a DataGrid. Here's one sequence (of a zillion) to
reproduce the problem:

1. call LoadData
2. call InsertRow function
3. edit a cell in the newly inserted row and press enter
4. edit a cell in the row below the inserted row and press enter
5. go yet another row down and edit a cell in that row . press enter.

... what happens now is that the cell on the current row loses its value (it
will say "(null)" ) and also a new identical row appears mysteriously below
(attempt to edit this row results in a 'System.NullReferenceException').

This problem can be reproduced by lots and lots of different combinations of
data and key sequences. I've also used ofther grids with identical results,
it seems like the problem somehow stems from the dataset-regions. Does
anyone know any way around this problem ? Has anyone ever gotten the
insertAt to work ?



<code>

Private ds As New DataSet

Private Sub LoadData()
ds.ReadXml("data.xml")
ds.ReadXmlSchema("schema.xml")
grid.DataSource = ds
End Sub


Private Sub InsertRow()
Dim dt As DataTable = ds.Tables("company")
Dim dr As DataRow = dt.NewRow()
dt.Rows.InsertAt(dr, 3)
dr.Item(0) = "Some text"
ds.AcceptChanges()
End Sub


Private Sub grid_CurrentCellChanged(ByVal sender As Object, ByVal e As
System.EventArgs) Handles grid.CurrentCellChanged
ds.AcceptChanges()
End Sub

</code>


Regards,
Peter


Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2009 codecomments.com