1.
Create
a project and add a Windows Form, then add a DataGrid, (DataGrid1), to it.
1.
Add
these 2 files, KDNGrid.vb and CGridNew.vb to the
project.
2.
Add
this “imports” statement to the Form: Imports WindowsApplication1.KnowDotNet.KDNGrid
(Note: Rename WindowsApplication1 to your project
name)
3.
Create
your DataSet that you will bind to the DataGrid. (objDs.tables(“MyTable”))
4.
Add
the sub below to your Form. Modify
the sub by changing the “ColumnX” to
fields in your dataset.
5.
Private Sub
LoadGridFromDB(ByVal DataSetTable)
'The
parameter passed in is the objDs.tables(“MyTable”) DataSet
'This
method loads the grid from a Microsoft Access Database
'Clear
any existing TableStyles
CGrid.ClearTableStyles(DataGrid1)
'Create
a TableStyle to which ColumnStyles will be added
Dim
ts As DataGridTableStyle =
CGrid.GetTableStyle(DataSetTable)
'TextBox
Column
Dim
cs1 As New
CGridTextBoxStyle("FullName", 80, HorizontalAlignment.Left, False, "Editable", String.Empty,
"")
CGrid.AddColumn(ts, cs1)
'Multiline
TextBox Column
Dim
cs2 As New
CGridMultiLineTextBoxStyle("Comment", 200, HorizontalAlignment.Left, False, "MultiLine Column", "")
CGrid.AddColumn(ts, cs2)
'CheckBox
Column
Dim
cs3 As New
CGridCheckBoxStyle("Active", 60, HorizontalAlignment.Center, False, "Check It!", "", False, True, False, False)
CGrid.AddColumn(ts, cs3)
'ComboBox
Column
Dim
Items() As String
= {"MIS", "Test Dev", "Admin"}
Dim
cs4 As New CGridComboBoxStyle("Department",
60, HorizontalAlignment.Left, "Select It!", "No", Items,
ComboBoxStyle.DropDownList)
CGrid.AddColumn(ts, cs4)
'NumericUpDown
Column
Dim
cs5 As New
CGridNumericUpDownStyle("SkillLevel", 60, "Skill Level", 0,
100, 0, 1, LeftRightAlignment.Right, 0, "#,##0")
CGrid.AddColumn(ts, cs5)
'Set
an AlternatingBackColor - just for looks
ts.AlternatingBackColor =
Color.LightGoldenrodYellow
'Set
the TableStyle for the Grid
CGrid.SetGridStyle(Me.DataGrid1, DataSetTable, ts)
'Prevent
the user from adding rows to the grid
CGrid.DisableAddNew(DataGrid1, Me)
'Turn
off the title bar for the grid
Me.DataGrid1.CaptionVisible
= False
End Sub