DataView mystery

M

Marina

Hi,

For some reasons, these lines of code sometimes differ in results:

myDataView.Item(1).row("MyColumn")
myDataView.Item(1)("MyColumn")

Sometimes the second version throws a NullReferenceException in the
System.Data.DataView.IsOriginalVersion(Int32 index) method. So the
DataRowView object being indexed to exists. And it definitely exists,
because the first version of the code works fine.

Can anyone tell me why going through the underlying row is OK, but not
through the indexer in datarowview directly?
 
C

Cor Ligthert

Marina,

For me is the behaviour of the insert weird.
With or without dataview.

You can try this than you see it direct what I mean

\\\Only a datagrid and a button on a form
Dim dt As New DataTable 'to be lazy
Private Sub Form1_Load(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles MyBase.Load
dt.Columns.Add("first")
dt.Columns.Add("Second")
dt.LoadDataRow(New String() {"Cor", "He likes Amsterdam"}, True)
DataGrid1.DataSource = dt 'remove this in the second try
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles Button1.Click
Dim dr As DataRow = dt.NewRow
dr.ItemArray = New String() {"Shahil", "He likes NewYork"}
dt.Rows.InsertAt(dr, 0)
DataGrid1.DataSource = Nothing
DataGrid1.DataSource = dt
End Sub
///
Remove the second time that instruction in the load event.
Than you see direct what I mean

Cor
 

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