I have a sdf database setup. The problem comes when I click the movenext button. SO when I keep Moving through the records it goes in this order: 23, 24, 25, 32, 26, 27, 28, 29, 30, 31, 33, 34... and so On. But its supposed to be 25, 26, 27, 28, 29, 30, 31, 32.. and so on right?
These numbers are auto generated record ID which are Incremented every new record
when i view the records in datagridview the order is good. So any ideas how i can resolve this?
UPDATE Sorry for the late reply. I have been trying to create an alternative route for record navigation so that it goes in order of the ID number. I have created a variable Cur_navID where the current records ID is saved. Every time next or previous buttons are pressed the next record in order will be displayed. But with thousands of record this method tends to be a bit vague. so anyways heres the main codes
Here is the code for:
New Record
Private Sub NewRecord()
If Not isEditing = True Then
Enable_edit()
id += 1
Me.BindingNavigatorAddNewItem.PerformClick()
Cust_nameTextBox.Clear()
ContactTextBox.Clear()
RemTextBox.Clear()
GradeTextBox.Clear()
SchoolTextBox.Clear()
V_numberTextBox.Clear()
Student_nameTextBox.Clear()
M7_idLabel1.Text = String.Format("{0:0000}", id)
date_pick.Value = DateTime.Now
StatusComboBox.SelectedIndex = 0
StatusComboBox.Text = "To Be Done"
setStatus(StatusComboBox.Text)
Cust_nameTextBox.Focus()
ElseIf isEditing = True Then
Dim di As DialogResult = MsgBox("Do you want to save the current record?", MsgBoxStyle.YesNoCancel)
If di = Windows.Forms.DialogResult.Yes Or di = Windows.Forms.DialogResult.OK Then
SaveRecord()
NewRecord()
ElseIf di = Windows.Forms.DialogResult.No Then
Canceledit()
ElseIf di = Windows.Forms.DialogResult.Cancel Then
Exit Sub
End If
End If
End Sub
Save Record
Private Sub SaveRecord()
Try
'// for customers with multiple lists. easier entry
lastmember.cust_name = Cust_nameTextBox.Text
lastmember.contact = ContactTextBox.Text
lastmember.grade = GradeTextBox.Text
lastmember.remks = RemTextBox.Text
Cust_nameTextBox.AutoCompleteSource = AutoCompleteSource.CustomSource
Cust_nameTextBox.AutoCompleteMode = AutoCompleteMode.SuggestAppend
Dim MySource As New AutoCompleteStringCollection()
MySource.Add(lastmember.cust_name)
Cust_nameTextBox.AutoCompleteCustomSource = MySource
Me.ListsBindingNavigatorSaveItem.PerformClick()
Disable_edit()
MsgBox("Record Saved!", MsgBoxStyle.Information)
'AppWait(700)
'ListsBindingSource.MoveLast()
Cust_nameTextBox.Focus()
Catch ex As Exception
' MsgBox("Please Fill in Customer Name, Contact and Grade Boxes", MsgBoxStyle.Information)
MsgBox(ex.Message, MsgBoxStyle.Information)
End Try
End Sub
Binding Navigator Save Item code
Private Sub ListsBindingNavigatorSaveItem_Click(sender As System.Object, e As System.EventArgs) Handles ListsBindingNavigatorSaveItem.Click
Me.Validate()
Me.ListsBindingSource.EndEdit()
Me.TableAdapterManager.UpdateAll(Me.BooksListDataSet)
My.Settings.ID = id
My.Settings.Save()
End Sub
And in form load event
' ### Load data into the 'BooksListDataSet.Lists' table.
Me.ListsTableAdapter.Fill(Me.BooksListDataSet.Lists)
Me.BindingNavigatorMoveLastItem.PerformClick()
' ### Update counter if database changed
Dim chek As Boolean = MAXID(BooksListDataSet.Tables("Lists")) = String.Format("{0:0000}", My.Settings.ID.ToString)
If chek = False Then
MsgBox("Database has been updated. Application will restart to compensate the changes.", MsgBoxStyle.Information)
' My.Settings.ID = Me.BooksListDataSet.Tables("Lists").Rows(BooksListDataSet.Tables("Lists").Rows.Count - 1).Item(0).ToString
My.Settings.ID = MAXID(BooksListDataSet.Tables("Lists"))
My.Settings.Save()
Application.Restart()
Else
End If
' ### Take backup
If My.Settings.backup_date = Nothing Then
Dim di As DialogResult = MsgBox("Do you want to create a backup database?", MsgBoxStyle.YesNoCancel)
If di = Windows.Forms.DialogResult.Yes Or di = Windows.Forms.DialogResult.OK Then
'//backup database
If Not My.Computer.FileSystem.FileExists(Path.Combine(Application.StartupPath.ToString, My.Settings.ID.ToString & "BooksList.sdf.BAK")) Then
My.Computer.FileSystem.CopyFile(Path.Combine(Application.StartupPath.ToString, "BooksList.sdf"), Path.Combine(Application.StartupPath.ToString, My.Settings.ID.ToString & "BooksList.sdf.BAK"))
My.Settings.backup_date = Date.Today
My.Settings.Save()
End If
Else
'do nothing
End If
ElseIf Not My.Settings.backup_date = Date.Today Or My.Computer.FileSystem.FileExists(Path.Combine(Application.StartupPath.ToString, My.Settings.ID.ToString & "BooksList.sdf.BAK")) = False Then
Dim di2 As DialogResult = MsgBox("Do you want to create todays backup database now?", MsgBoxStyle.YesNoCancel)
If di2 = Windows.Forms.DialogResult.Yes Or di2 = Windows.Forms.DialogResult.OK Then
'//backup database
If Not My.Computer.FileSystem.FileExists(Path.Combine(Application.StartupPath.ToString, My.Settings.ID.ToString & "BooksList.sdf.BAK")) Then
My.Computer.FileSystem.CopyFile(Path.Combine(Application.StartupPath.ToString, "BooksList.sdf"), Path.Combine(Application.StartupPath.ToString, My.Settings.ID.ToString & "BooksList.sdf.BAK"))
My.Settings.backup_date = Date.Today
My.Settings.Save()
End If
Else
'do nothing
End If
End If
' ### Load Autopcomplete list
Dim autocompleteList As New System.Windows.Forms.AutoCompleteStringCollection
Using reader As New System.IO.StreamReader("Schools.ACL")
While Not reader.EndOfStream
autocompleteList.Add(reader.ReadLine())
End While
End Using
SchoolTextBox.AutoCompleteSource = AutoCompleteSource.CustomSource
SchoolTextBox.AutoCompleteMode = AutoCompleteMode.Suggest
SchoolTextBox.AutoCompleteCustomSource = autocompleteList
' ### Focus next textbox on enter function part
textBoxes.Add(Cust_nameTextBox)
textBoxes.Add(ContactTextBox)
textBoxes.Add(RemTextBox)
textBoxes.Add(GradeTextBox)
textBoxes.Add(SchoolTextBox)
textBoxes.Add(V_numberTextBox)
textBoxes.Add(Student_nameTextBox)
Disable_edit()
Cur_navID = MAXID(Me.BooksListDataSet.Tables("Lists"))
Me.ListsBindingSource.Position = Cur_navID