Dear all;

I have using VB.Net and sql server to develop an application.

In the form I use controls to move record like First Rec, Previous Rec,
Next Rec, Last Rec. But I'm not using Navigator Binding control. It's mean
I use code to move.Anyone can help me, please.

Thank!
Kimlong

Can u show ur code and what controls are u using to show ur record???

Where do you want to put the record?

In my form I have. Three TextBoxes contain txtStaffCode, StaffName, Gender as ComboBox and other buttons to move records. Thoses buttons are btnFirst,btnNext,btnPrevious and btnLast. I already insert data into table(tblStaff). That's why when form_load I want to move record by clicking on each button then I want data to show in the textbox. For example first record is. StaffCode: STAFF-0001, StaffName: Khov Kimlong, Gender: Male. When I click Next button, Second record is: StaffCode: STAFF-0002, StaffName: Be Sreylin, and Gender: Female. Or further more.

Thank for your trying to help.

Note: I use the following code in VB 2008, I don't know the reason why it's not working
      on 2010 version.


Add a Listview Control then add the following Column (Staff Code, Staff Name and Gender)
after that declare a Global variable.

    Dim i As Integer = 0
    Dim NoOfItems As Integer = 0



and in you Form Load Event Populate the listview by getting the data from the Database,
after that Add the following code.

     ListView1.Items(0).Selected = True         ======> 'this will automatically selects
                                                ======>  'the first record in the listview

Let's Assume that your Listview item have a total number of 10 records

     'Remember That your Listview Start counting from 0
     '0,1,2,3,4,5,6,7,8,9     Total of 10 Records
     'and the code Val(ListView1.Items.Count) will produce 10

     NoOfItems = Val(ListView1.Items.Count) - 1  =====> 'this will get the total number
                                                 =====> 'of items in your listview


In your button Next I want you to Add the Following Code:


      i = Val(i) + 1

        If i > NoOfItems Then

           i = NoOfItems          =====> 'In case your i = 11 the last reocrd
                                  =====> 'we will set it back to 10 to avoid error


        msgbox("you have reached the last record")

       End If


    ListView1.SelectedItems.Clear() 
    ListView1.Items(i).Selected = True      =====> 'this will highlight your item in the
                                            =====> 'Listview



In your Previous Button Add the following code:


        i = Val(i) - 1

        If i < 0 Then

            i = 0

        End If
        o

Double Click your Listview and Add the Following Code:


      Private Sub ListView1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ListView1.SelectedIndexChanged

        Dim index As ListView.SelectedIndexCollection = ListView1.SelectedIndices

        Dim x As Integer = 0

        For Each x In index

            txtStaffCode.Text = ListView1.Items(x).SubItems(0).Text & ".)"
            txtStaffName.Text = ListView1.Items(x).SubItems(1).Text
            Gender.Text = ListView1.Items(x).SubItems(2).Text

        Next

    End Sub


 The Code Above will be responsible for changing the data in your Textbox every time you 
 Navigate Each record.

yes you can easily do this , first just add a bindingsource in your form and do like this.

dim con as new sqlconnection("your connection string")
dim dt as new datatable
con.open()
dim da as new sqldataadapter("select * from table1 ",con)
da.fill(dt)
bindingsource1.datasource=dt
con.close()

after this you can call following code , for move last , first , next , previous.

bindingsource1.movelast() 'this code is to move last
bindingsource1.movefirst() 'this code is to move first
bindingsource1.moveNext() 'this code is to move next
bindingsource1.movePrevious() 'this code is to move back
' as i am typing all this here so may be there is some mistake, so check it by your self.

Regards

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.