Link to home
Start Free TrialLog in
Avatar of brillox
brilloxFlag for United Kingdom of Great Britain and Northern Ireland

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(dsClients, "clients").Position < 0) Then
            MsgBox("Sorry, no more records", MsgBoxStyle.Exclamation)
        Else
            Me.BindingContext(dsClients, "Clients").Position = _
                           Me.BindingContext(dsClients, "Clients").Position - 1
        End If

        'update label records
        LabelShowRec.Text = "YOU ARE IN RECORD  " & (((Me.BindingContext(dsClients, "Clients").Position _
        + 1).ToString + "  OF   ") & Me.BindingContext(dsClients, _
        "Clients").Count.ToString)
    End Sub
Avatar of Jeff Certain
Jeff Certain
Flag of United States of America image

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...
Avatar of RonaldBiemans
RonaldBiemans

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(dsClients, "clients").Position = 0) Then
            MsgBox("Sorry, no more records", MsgBoxStyle.Exclamation)
        Else
            Me.BindingContext(dsClients, "Clients").Position = _
                           Me.BindingContext(dsClients, "Clients").Position - 1
        End If

        'update label records
        LabelShowRec.Text = "YOU ARE IN RECORD  " & (((Me.BindingContext(dsClients, "Clients").Position _
        + 1).ToString + "  OF   ") & Me.BindingContext(dsClients, _
        "Clients").Count.ToString)
    End Sub

for last record

    If (Me.BindingContext(dsClients, "clients").Position = 0) = cm.count - 1 then
  MsgBox("last record", MsgBoxStyle.Exclamation)
ASKER CERTIFIED SOLUTION
Avatar of RonaldBiemans
RonaldBiemans

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Bob Learned
I am not sure what the problem is, so here's my first guess:

    LabelShowRec.Text = "YOU ARE IN RECORD  " & Me.BindingContext(dsClients, "Clients").Position & " OF " & dsClients.Tables("Clients").Rows.Count

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
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
Avatar of brillox

ASKER

However, thanks also to Chaosian... I changed that pert of code as he suggested
Avatar of brillox

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