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?
06-30-2005, 04:33 PM
+Pablo
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
’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)
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)
07-01-2005, 12:03 PM
nickiii
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.