Question EndCurrentEdit does not stay in new record if Dataview is filtered

mbv

Member
Joined
Feb 11, 2009
Messages
6
Programming Experience
3-5
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. Also the application is attached: View attachment Form1.Designer.zip


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
 
Does the row you add pass the filter?

Hi Cjard What do you mean by "Pass" the filter? If this helps, when the row is added and then edited and the EndCurrentEdit command is executed, the DataView will assign the location to the row in accordance to the "Ordered" column. That is where the problem is as the current position may or may not be the position of the new record. The DataView in the posted code is not filtered.
 
You said you'd filtered, a row that does not pass a filter is hiddne. Suppose you were filtering on "hasEmail = true" and you entered a row that was hasEmail = false. It will disappear as soon as youre finished editing it.
Similarly for ordered, if you order by birthday, and you enter a new person who has a birthday somewher ein the middle of the set. When you commit the row, it will jump to the middle of the set. The focused row in the grid will probably stay on the end, or where you navigated to
 
You said you'd filtered, a row that does not pass a filter is hiddne. Suppose you were filtering on "hasEmail = true" and you entered a row that was hasEmail = false. It will disappear as soon as youre finished editing it.
Similarly for ordered, if you order by birthday, and you enter a new person who has a birthday somewher ein the middle of the set. When you commit the row, it will jump to the middle of the set. The focused row in the grid will probably stay on the end, or where you navigated to

Right. I mentioned that I filtered it. I am sorry I forgot I did. However, the example code does not include filtering the DataView as I realized filtering was just irrelevant to my problem.

As you pointed out, since the DataView is sorted, the focus/location of the new record may be lost. While this is a good way to describe my problem in different terms, it does not solve my problem (I don't mean to be rude ;) ). I am looking for an easy and safe way to ensure the new record stays focused no matter what the Order statement is (assuming that the filter does not exclude the new record)
 
Back
Top