Hi,
Check out this
Use Databinding context to bind your controls with the Dataset's table or view
Here is the sample code
Private _curManager As CurrencyManager ' declare it globally on top of ur form
Private Sub BindControls()
Dim dtSample As New DataTable
dtSample= Dataset.Tables(0) '<< Write your dataset's table here
txtGroupName.DataBindings.Add(New Binding("Text", dtSample, "GroupName"))
_curManager = CType(Me.BindingContext(dtSample), CurrencyManager)
_curManager.Position = 0
End Sub
Use Currency manager to Navigate your records
Here is the sample - code
Public Sub MoveToNextRecord(ByVal CurMgr As CurrencyManager)
If CurMgr.Position = CurMgr.Count - 1 Then
'MessageBox.Show("You are at end of the records.", Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Information)
Else
CurMgr.Position += 1
End If
End Sub
Public Sub MoveToFirstRecord(ByVal CurMgr As CurrencyManager)
CurMgr.Position = 0
End Sub
Public Sub MoveToLastRecord(ByVal CurMgr As CurrencyManager)
CurMgr.Position = CurMgr.Count - 1
End Sub
Public Sub MoveToPrevRecord(ByVal CurMgr As CurrencyManager)
If CurMgr.Position = 0 Then
'MessageBox.Show("You are at the beginning of the records.", Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Information)
Else
CurMgr.Position -= 1
End If
End Sub
Binding the Grid with Datasource
Private Sub BindGrid()
Dim dvMenu as dataview
dvMenu = Dataset.tables(0).DefaultViewManager
With <DataGridName>
.CaptionText = "XXXX"
.DataSource = _dvMenu
End With
Dim grdTableStyle1 As New DataGridTableStyle
With grdTableStyle1
.MappingName = _dvMenu.Table.TableName
.AlternatingBackColor = System.Drawing.Color.Silver
.BackColor = System.Drawing.Color.White
.GridLineStyle = System.Windows.Forms.DataGridLineStyle.None
.GridLineColor = Color.White
End With
If grdTableStyle1.RowHeadersVisible = True Then grdTableStyle1.RowHeaderWidth = 10 'grdTableStyle1.RowHeadersVisible = False
Dim grdCol1 As New DataGridTextBoxColumn
With grdCol1
.MappingName = "MENUID"
.HeaderText = "Menu ID"
.Width = 0
.ReadOnly = True
End With
Dim grdCol2 As New DataGridTextBoxColumn
With grdCol2
.MappingName = "MENUNAME"
.HeaderText = "Menu Name"
.Width = 180
'.Format = "c"
.ReadOnly = True
End With
Dim grdCol3 As New DataGridTextBoxColumn
With grdCol3
.MappingName = "FORMID"
.HeaderText = "Form Id"
.Width = 0
.ReadOnly = True
End With
grdTableStyle1.GridColumnStyles.AddRange(New DataGridColumnStyle() {grdCol1, grdCol2, grdCol14, grdCol3})
<YourDataGridName>.TableStyles.Add(grdTableStyle1)
End Sub
Record Count
Dataset.Tables(0).Rows.Count
DonRamesh
Enter your message below
Sign in or Join us (it's free).