Hi Guys,
Please help me. I am having a strange issue. Not sure if I am doing
something wrong or this is a bug.
This is a sample code.
This contains 2 text boxes(txtName, txtPhone) and 2 buttons (btnAdd,
btnSave)
Table(dtCustomers) contains three rows, with customer name "a", "b" and "c".
Now I press "btnAdd" button to add a new row.
Then I type "d" as name and "123" ad phone number.
Now I press save. That's when the problem occurs.
Momemt I press cm.EndCurrentEdit, it not only changes the position but it
also change the row. Instead of staying with customer "d" it goes to
customer "b".
And I have no clue why it goes to customer "d", when it should only change
the position based on the sort.
Please help me. I am stuck on this for some time now.
Let me know I need to include something. Please also let me know if you
cannot duplicate this issue.
I am using Visual Studio 2005 version 8.0.50727.762 (SP.050727-7600)
Dim cm As CurrencyManager
Dim dtCustomers As New DataTable
Sub New()
' This call is required by the Windows Form Designer.
InitializeComponent()
' Add any initialization after the InitializeComponent() call.
dtCustomers.Columns.Add("CustomerID", GetType(Integer))
dtCustomers.Columns.Add("Name", GetType(String))
dtCustomers.Columns.Add("Phone", GetType(String))
dtCustomers.Rows.Add(New Object() {1, "a", "1111"})
dtCustomers.Rows.Add(New Object() {2, "b", "2234567890"})
dtCustomers.Rows.Add(New Object() {3, "c", "3234567890"})
dtCustomers.DefaultView.Sort = "Phone"
cm = CType(Me.BindingContext(dtCustomers.DefaultView),
CurrencyManager)
Me.txtName.DataBindings.Add("Text", dtCustomers.DefaultView, "Name")
Me.txtPhone.DataBindings.Add("Text", dtCustomers.DefaultView,
"Phone")
dtCustomers.Columns("CustomerID").DefaultValue = -1
End Sub
Private Sub btnAdd_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnAdd.Click
Me.cm.AddNew()
End Sub
Private Sub btnSave_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnSave.Click
Dim _CustomerID As Integer = Me.cm.Current("CustomerID")
Me.cm.EndCurrentEdit()
If Me.cm.Current("CustomerID") <_CustomerID Then
Stop
Exit Sub
End If
End Sub