// Please use the following namespace
// using System.Windows.Forms;
// using System.Data;
// using GrapeCity.Win.Editors;
public void SetDataSourceSettings()
{
// Creates the GcListBox control.
GcListBox gcListBox1 = new GcListBox();
// Create a new DataSet
DataSet dataSet = this.CreateDataSet();
// Sets the AutoGenerateColumns to true in order to generates columns according
// the data source.
gcListBox1.AutoGenerateColumns = true;
// Sets the DataSource to a DataSet.
gcListBox1.DataSource = dataSet;
// Sets the DataMember to a table name.
gcListBox1.DataMember = "Table";
// Sets the TextSubItemIndex to 0.
// The Text property retrieves the value of the first column in the selected row.
gcListBox1.TextSubItemIndex = 0;
// Sets the TextSubItemIndex to 0.
// The SelectedValue property retrieves the value of the second column in the selected row.
gcListBox1.ValueSubItemIndex = 1;
}
private DataSet CreateDataSet()
{
// Create a new DataSet
DataSet dataSet = new DataSet();
// Create a new DataTable.
System.Data.DataTable table = new DataTable("Table");
// Declare variables for DataColumn and DataRow objects.
DataColumn column;
DataRow row;
dataSet.Tables.Add(table);
// Create new DataColumn, set DataType,
// ColumnName and add to DataTable.
column = new DataColumn();
column.DataType = System.Type.GetType("System.Int32");
column.ColumnName = "id";
column.ReadOnly = true;
column.Unique = true;
// Add the Column to the DataColumnCollection.
table.Columns.Add(column);
// Create second column.
column = new DataColumn();
column.DataType = System.Type.GetType("System.String");
column.ColumnName = "Item";
column.AutoIncrement = false;
column.Caption = "Item";
column.ReadOnly = false;
column.Unique = false;
// Add the column to the table.
table.Columns.Add(column);
// Make the ID column the primary key column.
DataColumn[] PrimaryKeyColumns = new DataColumn[1];
PrimaryKeyColumns[0] = table.Columns["id"];
table.PrimaryKey = PrimaryKeyColumns;
// Create three new DataRow objects and add
// them to the DataTable
for (int i = 0; i <= 2; i++)
{
row = table.NewRow();
row["id"] = i;
row["Item"] = "Item " + i;
table.Rows.Add(row);
}
return dataSet;
}
' Please use the following namespace
' Imports System.Windows.Forms;
' Imports System.Data;
' Imports GrapeCity.Win.Editors;
Public Sub SetDataSourceSettings()
' Creates the GcListBox control.
Dim gcListBox1 As New GcListBox()
' Create a new DataSet
Dim dataSet As DataSet = Me.CreateDataSet()
' Sets the AutoGenerateColumns to true in order to generates columns according
' the data source.
gcListBox1.AutoGenerateColumns = True
' Sets the DataSource to a DataSet.
gcListBox1.DataSource = dataSet
' Sets the DataMember to a table name.
gcListBox1.DataMember = "Table"
' Sets the TextSubItemIndex to 0.
' The Text property retrieves the value of the first column in the selected row.
gcListBox1.TextSubItemIndex = 0
' Sets the TextSubItemIndex to 0.
' The SelectedValue property retrieves the value of the second column in the selected row.
gcListBox1.ValueSubItemIndex = 1
End Sub
Private Function CreateDataSet() As DataSet
' Create a new DataSet
Dim dataSet As New DataSet()
' Create a new DataTable.
Dim table As System.Data.DataTable = New DataTable("Table")
' Declare variables for DataColumn and DataRow objects.
Dim column As DataColumn
Dim row As DataRow
dataSet.Tables.Add(table)
' Create new DataColumn, set DataType,
' ColumnName and add to DataTable.
column = New DataColumn()
column.DataType = System.Type.[GetType]("System.Int32")
column.ColumnName = "id"
column.[ReadOnly] = True
column.Unique = True
' Add the Column to the DataColumnCollection.
table.Columns.Add(column)
' Create second column.
column = New DataColumn()
column.DataType = System.Type.[GetType]("System.String")
column.ColumnName = "Item"
column.AutoIncrement = False
column.Caption = "Item"
column.[ReadOnly] = False
column.Unique = False
' Add the column to the table.
table.Columns.Add(column)
' Make the ID column the primary key column.
Dim PrimaryKeyColumns As DataColumn() = New DataColumn(0) {}
PrimaryKeyColumns(0) = table.Columns("id")
table.PrimaryKey = PrimaryKeyColumns
' Create three new DataRow objects and add
' them to the DataTable
Dim i As Integer = 0
While i <= 2
row = table.NewRow()
row("id") = i
row("Item") = "Item " + i
table.Rows.Add(row)
System.Math.Max(System.Threading.Interlocked.Increment(i), i - 1)
End While
Return dataSet
End Function