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(dtCustome rs) 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.EndCurrentEd it, 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.
InitializeCompo nent()
' Add any initialization after the InitializeCompo nent() call.
dtCustomers.Col umns.Add("Custo merID", GetType(Integer ))
dtCustomers.Col umns.Add("Name" , GetType(String) )
dtCustomers.Col umns.Add("Phone ", GetType(String) )
dtCustomers.Row s.Add(New Object() {1, "a", "1111"})
dtCustomers.Row s.Add(New Object() {2, "b", "2234567890 "})
dtCustomers.Row s.Add(New Object() {3, "c", "3234567890 "})
dtCustomers.Def aultView.Sort = "Phone"
cm = CType(Me.Bindin gContext(dtCust omers.DefaultVi ew),
CurrencyManager )
Me.txtName.Data Bindings.Add("T ext", dtCustomers.Def aultView, "Name")
Me.txtPhone.Dat aBindings.Add(" Text", dtCustomers.Def aultView,
"Phone")
dtCustomers.Col umns("CustomerI D").DefaultValu e = -1
End Sub
Private Sub btnAdd_Click(By Val sender As System.Object, ByVal e As
System.EventArg s) Handles btnAdd.Click
Me.cm.AddNew()
End Sub
Private Sub btnSave_Click(B yVal sender As System.Object, ByVal e As
System.EventArg s) Handles btnSave.Click
Dim _CustomerID As Integer = Me.cm.Current(" CustomerID")
Me.cm.EndCurren tEdit()
If Me.cm.Current(" CustomerID") <_CustomerID Then
Stop
Exit Sub
End If
End Sub
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(dtCustome rs) 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.EndCurrentEd it, 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.
InitializeCompo nent()
' Add any initialization after the InitializeCompo nent() call.
dtCustomers.Col umns.Add("Custo merID", GetType(Integer ))
dtCustomers.Col umns.Add("Name" , GetType(String) )
dtCustomers.Col umns.Add("Phone ", GetType(String) )
dtCustomers.Row s.Add(New Object() {1, "a", "1111"})
dtCustomers.Row s.Add(New Object() {2, "b", "2234567890 "})
dtCustomers.Row s.Add(New Object() {3, "c", "3234567890 "})
dtCustomers.Def aultView.Sort = "Phone"
cm = CType(Me.Bindin gContext(dtCust omers.DefaultVi ew),
CurrencyManager )
Me.txtName.Data Bindings.Add("T ext", dtCustomers.Def aultView, "Name")
Me.txtPhone.Dat aBindings.Add(" Text", dtCustomers.Def aultView,
"Phone")
dtCustomers.Col umns("CustomerI D").DefaultValu e = -1
End Sub
Private Sub btnAdd_Click(By Val sender As System.Object, ByVal e As
System.EventArg s) Handles btnAdd.Click
Me.cm.AddNew()
End Sub
Private Sub btnSave_Click(B yVal sender As System.Object, ByVal e As
System.EventArg s) Handles btnSave.Click
Dim _CustomerID As Integer = Me.cm.Current(" CustomerID")
Me.cm.EndCurren tEdit()
If Me.cm.Current(" CustomerID") <_CustomerID Then
Stop
Exit Sub
End If
End Sub