Previous & Next Record


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 3 of 3

Thread: Previous & Next Record

  1. #1
    Join Date
    Mar 2005
    Posts
    105

    Previous & Next Record

    I need to add 'next' and 'previous' buttons toa VB.NET project. I plan to grab the dataset get the current record and possible increment/decrement my way thru them. The table shows a list of customers. After clicking a record a customer details screen appears. This is where I want to add the 'next' and 'previous' buttons.

    Any theoretical ideas on how to proceed?

  2. #2
    Join Date
    Apr 2005
    Posts
    39
    hope this code can help you

    read this if this not, ask again

    Code:
    Dim intOldRow As Integer
    Private Sub Form3_Load(ByVal sender As System.Object, _
        ByVal e As System.EventArgs) Handles MyBase.Load
    
        ’Populate DataGrid1.
        OleDbDataAdapter1.Fill(DsOrderDetails1, _
            "Order Details")
        DataGrid1.DataSource = _
            DsOrderDetails1.Tables("Order Details")
    
        ’Position current cell in OrderID column
        ’of the first row and save row position.
        DataGrid1.CurrentCell = New DataGridCell(0, 1)
        intOldRow = DataGrid1.CurrentRowIndex
    
        ’Reset grid size to show data without horizontal
        ’scrolling and update form size for grid.
        DataGrid1.Size = _
            New System.Drawing.Size(448, DataGrid1.Height)
        Me.Size = New System.Drawing.Size(470, 300)
    
        ’Set properties for navigation buttons.
        Button1.Height = TextBox1.Height
        Button2.Height = TextBox1.Height
        Button3.Height = TextBox1.Height
        Button4.Height = TextBox1.Height
        Button1.Text = "<<"
        Button2.Text = "<"
        Button3.Text = ">"
        Button4.Text = ">>"
    
        ’Set properties for Go To record button.
        Button5.Text = "Go to"
        Button5.Size = _
            New System.Drawing.Size(42, TextBox1.Height)
    
        ’Text and TextAlign property settings for labels
        Label1.Text = "OrderID"
        Label2.Text = "Price"
        Label1.TextAlign = ContentAlignment.MiddleRight
        Label2.TextAlign = ContentAlignment.MiddleRight
    
        ’Position labels relative to corresponding
        ’text boxes.
        Label1.Height = TextBox2.Height
        Label1.Top = TextBox2.Top - Label1.Height
        Label2.Height = TextBox3.Height
        Label2.Top = TextBox3.Top - Label1.Height
    
    End Sub
    
    Private Sub DataGrid1_CurrentCellChanged( _
        ByVal sender As Object, _
        ByVal e As System.EventArgs) _
        Handles DataGrid1.CurrentCellChanged
    
        ’Create a pointer for the DataGrid control.
        Dim dg As DataGrid
        dg = DataGrid1
    
        ’Compute text box display showing current row
        ’relative to total number of rows.
        UpdatePositionIndicator(dg)
    
        ’Display the OrderID for the current row.
        TextBox2.Text = _
            dg(dg.CurrentCell.RowNumber, 1).ToString
        TextBox2.TextAlign = HorizontalAlignment.Right
    
        ’Computation throws error if selection is
        ’out of bounds.
        Try
            ’Compute and display extended price for
            ’the current row.
            TextBox3.Text = _
                Format( _
                dg(dg.CurrentCell.RowNumber, 3) * _
                dg(dg.CurrentCell.RowNumber, 4) * _
                (1 - dg(dg.CurrentCell.RowNumber, 0)) _
                , "C").ToString
            TextBox3.TextAlign = HorizontalAlignment.Right
            ’If error is InvalidCastException, reset position
            ’to last valid row; otherwise, display error.
        Catch er As System.InvalidCastException
            dg.CurrentCell = _
                New DataGridCell(intOldRow, _
                dg.CurrentCell.ColumnNumber)
        Catch er As System.Exception
            MsgBox(er.Message & vbCr & er.ToString & _
                vbCr & "Reset row application manually.")
            Exit Try
        Finally
            ’In any event, save row position.
            intOldRow = dg.CurrentRowIndex
        End Try
    
    End Sub
    
    Sub UpdatePositionIndicator(ByVal dg As DataGrid)
    
        ’Update position display in TextBox1.
        TextBox1.Text = _
            (dg.CurrentCell.RowNumber + 1).ToString & _
            " of " & DsOrderDetails1. _
            Tables("Order Details").Rows.Count
        TextBox1.TextAlign = HorizontalAlignment.Right
    
    End Sub
    
    Private Sub Button1_Click(ByVal sender As System.Object, _
        ByVal e As System.EventArgs) Handles Button1.Click
    
        ’Move to first row and save row position.
        DataGrid1.CurrentRowIndex = 0
        intOldRow = DataGrid1.CurrentRowIndex
    
    End Sub
    
    Private Sub Button2_Click(ByVal sender As System.Object, _
        ByVal e As System.EventArgs) Handles Button2.Click
    
        ’Move backward one row if not already at
        ’first row, and save row position.
        If DataGrid1.CurrentRowIndex > 0 Then
            DataGrid1.CurrentRowIndex -= 1
            intOldRow = DataGrid1.CurrentRowIndex
        End If
    
    End Sub
    
    Private Sub Button3_Click(ByVal sender As System.Object, _
        ByVal e As System.EventArgs) Handles Button3.Click
    
        ’Move forward one row if not already at
        ’last row, and save row position.
        If DataGrid1.CurrentRowIndex < DsOrderDetails1. _
            Tables("Order Details").Rows.Count - 1 Then
            DataGrid1.CurrentRowIndex += 1
            intOldRow = DataGrid1.CurrentRowIndex
        End If
    
    End Sub
    
    Private Sub Button4_Click(ByVal sender As System.Object, _
        ByVal e As System.EventArgs) Handles Button4.Click
    
        ’Move to last row and save row position.
        DataGrid1.CurrentRowIndex = DsOrderDetails1. _
            Tables("Order Details").Rows.Count - 1
        intOldRow = DataGrid1.CurrentRowIndex
    
    End Sub
    
    Private Sub Button5_Click(ByVal sender As System.Object, _
        ByVal e As System.EventArgs) Handles Button5.Click
    
        ’Set pointer for new row value.
        Dim int1 = CInt(TextBox1.Text) - 1
    
        ’Go to designated row, and save row position or
        ’restore old row position.
        If int1 >= 0 And int1 <= DsOrderDetails1. _
            Tables("Order Details").Rows.Count - 1 Then
            DataGrid1.CurrentRowIndex = int1
            intOldRow = DataGrid1.CurrentRowIndex
        Else
            DataGrid1.CurrentRowIndex = intOldRow
        End If
    
        ’Compute text box display showing current row
        ’relative to total number of rows.
        UpdatePositionIndicator(DataGrid1)
    "Quid quid agis prudenter agas et respice finem"
    (Hagas lo que hagas, actúa inteligentemente y considerando el fin)
    MyNeoReport - The "FREE" Report Generator for .NET
    http://myneoreport.sourceforge.net/
    http://www.frappr.com/vbcity

  3. #3
    Join Date
    Mar 2005
    Posts
    105
    The original developer used a 3rd party tool called Infragistics. With it he used an UltraGrid and it seems a little unconventional. Guess I need to dig a little deeper and research this UltraGrid.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center