Steven Low
Active member
- Joined
- Apr 14, 2005
- Messages
- 42
- Programming Experience
- 1-3
Hi Guys
Im am trying to get the next button and previouse button to work properly with validations. Ive created a method SetButtonState which handles the button state. I am having a problem with the next button. Cant get it to work properly. I want it to start from the start and end at the last row. Theres a total of 5 rows...
Need help
Im am trying to get the next button and previouse button to work properly with validations. Ive created a method SetButtonState which handles the button state. I am having a problem with the next button. Cant get it to work properly. I want it to start from the start and end at the last row. Theres a total of 5 rows...
Need help
VB.NET:
Code:
Private Sub btnNext_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnNext.Click
'Show the next record if the current one is not the last
Dim connStr As String = ("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Project\proj.mdb;")
Dim sqlStr As String = "SELECT * FROM Student"
Dim dataAdapter As New OleDb.OleDbDataAdapter(sqlStr, connStr)
'Show the next record if the current one is not the last
dataAdapter.Fill(dt)
dataAdapter.Dispose()
UpdateTextBoxes()
If (rowIndex < dt.Rows.Count - 1) Then
rowIndex += 1 'Increase the rowIndex by 1
'MessageBox.Show("thats it")
UpdateTextBoxes()
shows()
End If
SetButtonState(rowIndex, dt.Rows.Count)
End Sub
Private Sub btnPrevious_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnPrevious.Click
'Show the previous record if the current one is not the first
Dim connStr As String = ("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C[IMG]http://www.vbcity.com/forums/smiles/tongue.gif[/IMG]roj.mdb;")
Dim sqlStr As String = "SELECT * FROM Student"
Dim dataAdapter As New OleDb.OleDbDataAdapter(sqlStr, connStr)
dataAdapter.Fill(dt)
dataAdapter.Dispose()
UpdateTextBoxes()
If (rowIndex > 0) Then
rowIndex = rowIndex - 1
UpdateTextBoxes()
End If
SetButtonState(rowIndex, dt.Rows.Count)
End Sub
Private Sub SetButtonState(ByVal CurrRowIndex As String, ByVal NumberOfRows As String)
'Set the Previous Button State
Select Case True
Case CurrRowIndex = 0
'Indicates its on the first row
btnPrevious.Enabled = False
Case NumberOfRows = 1
'There is only 1 row in the DataTable
btnPrevious.Enabled = False
Case Else
btnPrevious.Enabled = True
End Select
'Set the Next Button State
Select Case True
Case NumberOfRows = 1
'There is only 1 row in the DataTable
btnNext.Enabled = False
Case CurrRowIndex = NumberOfRows - 1
'Currently on the last Row
btnNext.Enabled = False
Case Else
btnNext.Enabled = True
End Select
End Sub