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)