M B

M B

  • NA
  • 5
  • 0

EndCurrentEdit does not stay in new record if Dataview is filtered vb.net

Apr 29 2010 8:37 AM
I have an application with a "filtered" DataView. The Dataview is bound to a form through a CurrencyManager. The problem is that when I add a new record using CurrMgr.AddNew(), and then use the CurrMgr.EndCurrentEdit() before saving the new record, the currency manager will point inmediatelly to the last record. How can I ensure the currency manager stays in the new record?. The code below proves the issue. I could add some code to find the record, but there should be an easier way to achieve this.
 
Public Class Form1
Public Class Form1
Private CurrMgr As CurrencyManager
Private DtVw As DataView
Private tbl As New DataTable("tbl1")

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'THE TABLE
tbl.Columns.Add("Col1", System.Type.GetType("System.String"))
DtVw = New DataView(tbl)
DtVw.Sort = "Col1"
Dim row As DataRow = tbl.NewRow
row(0) = "A" tbl.Rows.Add(row)
row = tbl.NewRow
row(0) = "Z" tbl.Rows.Add(row)
'CURRENCY MANAGER
CurrMgr = CType(Me.BindingContext(DtVw), CurrencyManager)
'Bind Control
Dim b As Binding = New Binding("Text", DtVw, "Col1")
TextBox1.DataBindings.Add(b)
End Sub

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
CurrMgr.AddNew()
End Sub

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
CurrMgr.EndCurrentEdit()
End Sub

End Class
 

Attachment: Form1.Designer.zip