Greeting.
I'm working on my
vb.net 2005 project and linking to SQL server 2000 for my database.
I have a master user form which having a bindingnavigator binding to a binding source control to user class's datatable.
I got a problem on the bindingnavigator. when I'm trying to addnew record. the bindingnavigator's positionitem textbox shows 2 extra new record as it suppose to have only 1 new row increase.
below is my code to add new row. Please advice.
''my Form's sub
Private Sub frmUser_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Try
Dim success As Boolean
success = mUser.LoadAll
If Not success Then
Throw New Exception("Failed to Load All record.")
Else
BindingSource1.DataSource = mUser.dataTable
BindingNavigator1.BindingSource = BindingSource1
Bind() 'Bind to all my input textboxes
End If
Catch ex As Exception
MsgBox(ex.Message)
End Try
End Sub
Private Sub BindingNavigatorAddNewItem_Click(ByVal sender As system.Object, ByVal e As System.EventArgs) Handles BindingNavigatorAddNewItem.Click
mUser.AddNew()
End Sub
''my user class's addnew function
Public dataTable As DataTable = New DataTable
Public currentRow As DataRow = Nothing
Public Overridable Sub AddNew()
currentRow = dataTable.NewRow()
dataTable.Rows.Add(currentRow)
End Sub
Public Overridable Function LoadAll() As Boolean
Try
Dim success As Boolean = False
Dim cmd As SqlCommand = New SqlCommand
cmd.Connection = New SqlConnection(gConnStr)
cmd.CommandType = CommandType.StoredProcedure
cmd.CommandText = "[SP000STDUSERLoadAll]"
If dataTable.Rows.Count > 0 Then
currentRow = dataTable.Rows(0)
success = True
End If
Return success
Catch ex As Exception
End Try
End Function