I
IraG
Say you have a sorted DataView, and create a DataRowView that points to
a particular row in this DataView.
If you edit the DataRowView and change its contents so that it re-sorts
into a different position in the DataView, the result is that the
DataRowView will now point to a *different* row in the DataView (the
row that now occupies the same position as the original DataRowView
before the edit that caused it to sort to a different position).
Is this a bug, or a feature?
It's possible that this behavior was present prior to VS 2005, but I
never noticed it.
It seems is that a DataRowView always points to a row with a particular
fixed index location in a DataView. So if rows get re-sorted in a
DataView, a DataRowView can potentially point to a different row. But
I have seen no references anywhere to this behavior.
Dim dt As New DataTable
Dim dr As DataRow
dt.Columns.Add("Col1", GetType(String))
dr = dt.NewRow
dr("Col1") = "D"
dt.Rows.Add(dr)
dr = dt.NewRow
dr("Col1") = "E"
dt.Rows.Add(dr)
Dim dv As DataView = dt.DefaultView
dv.Sort = "Col1 ASC"
Dim drv As DataRowView = dv(1)
Dim drSave As DataRow = drv.Row
Console.WriteLine(drv("Col1")) ' displays "E", as expected
Console.WriteLine((drSave Is drv.Row).ToString) ' displays "True"
drv.BeginEdit()
drv("Col1") = "A" ' change alphabetical order of the last row
Console.WriteLine(drv("Col1")) ' displays "A", as expected
drv.EndEdit()
' EndEdit results in the dt.DefaultView getting re-sorted, with
the
' last row becoming the first row. But drv is now the *new* last
row,
' even though the dataview row that it previously pointed to is now
' drv(0). That is, the EndEdit causes drv to represent an entirely
' different row in the dataview.
Console.WriteLine(drv("Col1")) ' displays "D", not "A" !!!!!!
' drv.Row is no long the same row as it was before the sort column
' was updated
Console.WriteLine((drSave Is drv.Row).ToString) ' displays "False"
a particular row in this DataView.
If you edit the DataRowView and change its contents so that it re-sorts
into a different position in the DataView, the result is that the
DataRowView will now point to a *different* row in the DataView (the
row that now occupies the same position as the original DataRowView
before the edit that caused it to sort to a different position).
Is this a bug, or a feature?
It's possible that this behavior was present prior to VS 2005, but I
never noticed it.
It seems is that a DataRowView always points to a row with a particular
fixed index location in a DataView. So if rows get re-sorted in a
DataView, a DataRowView can potentially point to a different row. But
I have seen no references anywhere to this behavior.
Dim dt As New DataTable
Dim dr As DataRow
dt.Columns.Add("Col1", GetType(String))
dr = dt.NewRow
dr("Col1") = "D"
dt.Rows.Add(dr)
dr = dt.NewRow
dr("Col1") = "E"
dt.Rows.Add(dr)
Dim dv As DataView = dt.DefaultView
dv.Sort = "Col1 ASC"
Dim drv As DataRowView = dv(1)
Dim drSave As DataRow = drv.Row
Console.WriteLine(drv("Col1")) ' displays "E", as expected
Console.WriteLine((drSave Is drv.Row).ToString) ' displays "True"
drv.BeginEdit()
drv("Col1") = "A" ' change alphabetical order of the last row
Console.WriteLine(drv("Col1")) ' displays "A", as expected
drv.EndEdit()
' EndEdit results in the dt.DefaultView getting re-sorted, with
the
' last row becoming the first row. But drv is now the *new* last
row,
' even though the dataview row that it previously pointed to is now
' drv(0). That is, the EndEdit causes drv to represent an entirely
' different row in the dataview.
Console.WriteLine(drv("Col1")) ' displays "D", not "A" !!!!!!
' drv.Row is no long the same row as it was before the sort column
' was updated
Console.WriteLine((drSave Is drv.Row).ToString) ' displays "False"