brillox
asked on
adding a message to first and last record methods
Bsically I would like to add a message when the first and last records hits their limits
eg if the user keep pressing on previous record button, but he/she is already at the first record, I would like to display a message saying ... bla bla you are already there.. I tried this but... it does not work
Private Sub ButtonPrevious_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ButtonPrevious.Click
'go to previous record
If (Me.BindingContext(dsClien ts, "clients").Position < 0) Then
MsgBox("Sorry, no more records", MsgBoxStyle.Exclamation)
Else
Me.BindingContext(dsClient s, "Clients").Position = _
Me.BindingContext(dsClient s, "Clients").Position - 1
End If
'update label records
LabelShowRec.Text = "YOU ARE IN RECORD " & (((Me.BindingContext(dsCli ents, "Clients").Position _
+ 1).ToString + " OF ") & Me.BindingContext(dsClient s, _
"Clients").Count.ToString)
End Sub
eg if the user keep pressing on previous record button, but he/she is already at the first record, I would like to display a message saying ... bla bla you are already there.. I tried this but... it does not work
Private Sub ButtonPrevious_Click(ByVal
'go to previous record
If (Me.BindingContext(dsClien
MsgBox("Sorry, no more records", MsgBoxStyle.Exclamation)
Else
Me.BindingContext(dsClient
Me.BindingContext(dsClient
End If
'update label records
LabelShowRec.Text = "YOU ARE IN RECORD " & (((Me.BindingContext(dsCli
+ 1).ToString + " OF ") & Me.BindingContext(dsClient
"Clients").Count.ToString)
End Sub
Why not just disable those buttons based on the current position of the record they are viewing? If they're on record 0, then disable the first/previous buttons; if they're on record datatable.count-1, then disable the last/next buttons. If count =0 then disable all buttons, since there are no records...
change to
Private Sub ButtonPrevious_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ButtonPrevious.Click
'go to previous record
If (Me.BindingContext(dsClien ts, "clients").Position = 0) Then
MsgBox("Sorry, no more records", MsgBoxStyle.Exclamation)
Else
Me.BindingContext(dsClient s, "Clients").Position = _
Me.BindingContext(dsClient s, "Clients").Position - 1
End If
'update label records
LabelShowRec.Text = "YOU ARE IN RECORD " & (((Me.BindingContext(dsCli ents, "Clients").Position _
+ 1).ToString + " OF ") & Me.BindingContext(dsClient s, _
"Clients").Count.ToString)
End Sub
for last record
If (Me.BindingContext(dsClien ts, "clients").Position = 0) = cm.count - 1 then
MsgBox("last record", MsgBoxStyle.Exclamation)
Private Sub ButtonPrevious_Click(ByVal
'go to previous record
If (Me.BindingContext(dsClien
MsgBox("Sorry, no more records", MsgBoxStyle.Exclamation)
Else
Me.BindingContext(dsClient
Me.BindingContext(dsClient
End If
'update label records
LabelShowRec.Text = "YOU ARE IN RECORD " & (((Me.BindingContext(dsCli
+ 1).ToString + " OF ") & Me.BindingContext(dsClient
"Clients").Count.ToString)
End Sub
for last record
If (Me.BindingContext(dsClien
MsgBox("last record", MsgBoxStyle.Exclamation)
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
I am not sure what the problem is, so here's my first guess:
LabelShowRec.Text = "YOU ARE IN RECORD " & Me.BindingContext(dsClient s, "Clients").Position & " OF " & dsClients.Tables("Clients" ).Rows.Cou nt
To make references easier, you might want to look into the CurrencyManager class:
Bind a CurrencyManager to objects in a collection and use it for navigation in VB .NET
http://www.vb-helper.com/howto_net_bind_collection.html
Bob
LabelShowRec.Text = "YOU ARE IN RECORD " & Me.BindingContext(dsClient
To make references easier, you might want to look into the CurrencyManager class:
Bind a CurrencyManager to objects in a collection and use it for navigation in VB .NET
http://www.vb-helper.com/howto_net_bind_collection.html
Bob
Chaosians suggestion is ofcourse more professional :-)
Hello, Ronald, I swore that I hit the <Refresh> button :)
Bob
Bob
Ronald...
Don't know about professional... I just have users who try to do creative things to my software... so I try to remove all the options that would allow them to break things. <grin />
Jeff
Don't know about professional... I just have users who try to do creative things to my software... so I try to remove all the options that would allow them to break things. <grin />
Jeff
ASKER
However, thanks also to Chaosian... I changed that pert of code as he suggested
ASKER
I still do not understand if and when I should call
DataADapter.DIspose
DataADapter = Nothing
Connection.DIspose() Command.DIpsose() etc etc
I realize that If I do not have a dataAdapter or command etc I do not have to bother but If I have it when I should call those methods
DataADapter.DIspose
DataADapter = Nothing
Connection.DIspose() Command.DIpsose() etc etc
I realize that If I do not have a dataAdapter or command etc I do not have to bother but If I have it when I should call those methods