Home Forums WinForms controls Xceed Grid for WinForms runtime checkbox column Reply To: runtime checkbox column

Xceed Support
Member
Post count: 5658

Here is some sample code with a 2-columns DataTable (1 Boolean column and 1 Integer column). You can edit both column’s value.

<code>
private void Form1_Load( object sender, EventArgs e )
{
//Create a DataTable
DataTable dt = new DataTable();
DataColumn dcBool = new DataColumn();
dcBool.ColumnName = “BoolColumn”;
dcBool.DataType = System.Type.GetType( “System.Boolean” );
dt.Columns.Add( dcBool );

DataColumn dcInt = new DataColumn();
dcInt.ColumnName = “IntColumn”;
dcInt.DataType = System.Type.GetType( “System.Int32” );
dt.Columns.Add( dcInt );

for( int i = 0; i < 50; i++ )
{
System.Data.DataRow row = dt.NewRow();
int j = i % 3;

if( j == 0 )
{
row[ “BoolColumn” ] = false;
row[ “IntColumn” ] = 0;
}
else if( j == 1 )
{
row[ “BoolColumn” ] = true;
row[ “IntColumn” ] = 1;
}
else
{
row[ “BoolColumn” ] = DBNull.Value;
row[ “IntColumn” ] = DBNull.Value;
}

dt.Rows.Add( row );
}

gridControl1.DataSource = dt;

gridControl1.Columns[ “IntColumn” ].CellEditorManager = new CheckBoxEditor();
gridControl1.Columns[ “IntColumn” ].CellViewerManager = new CheckBoxViewer();
}
</code>

Imported from legacy forums. Posted by CharlesB (had 4846 views)