display checkbox in datagrid.

M

michael walser

display checkbox in datagrid.

I find that there are 3 status:
checked - check box with click icon
unchecked - blank in check box
unknown - click icon but color in gray.....

How can I set the check box only 2 status, checked and unchecked?


Here my code:
==========
private void CreateMyDatagrid()

{

// MyDatagrid erstellen

DataGrid MyDataGrid = new DataGrid();

MyDataGrid.Bounds = new Rectangle(new Point(10,10), new Size(650,350));

// Datagrid Eigenschaften

MyDataGrid.CaptionText="Berechtigung";

// Dataset erstellen

DataSet MyDataSet = new DataSet();


DataGridTableStyle myTableStyle = new DataGridTableStyle();

myTableStyle.MappingName = "MappingName_ts_berechtigung";

DataGridBoolColumn boolCol = new DataGridBoolColumn();

boolCol.MappingName="ALLE";

((DataGridBoolColumn)boolCol).AllowNull = false;

myTableStyle.GridColumnStyles.Add(boolCol);

MyDataGrid.TableStyles.Clear();

MyDataGrid.TableStyles.Add(myTableStyle);

// DataTable erstellen

DataTable dt = new DataTable("DataTable_Berechtigung");

// Datagrid Spalten Formatieren

MyDataGrid.TableStyles["DataTable_Berechtigung"].GridColumnStyles["ALLE"].Wi
dth = 250;


// Spalten erstellen

dt.Columns.Add("Modul", typeof(string)).ReadOnly = true;

dt.Columns.Add("Zusatz...", typeof(string)).ReadOnly = true;

dt.Columns.Add("ALLE", typeof(bool));

dt.Columns.Add("Ansehen", typeof(bool));

dt.Columns.Add("Bearbeiten", typeof(bool));

dt.Columns.Add("Erstellen", typeof(bool));

dt.Columns.Add("Löschen", typeof(bool));


//Spaltenbreite definieren

MyDataGrid.TableStyles["DataTable_Berechtigung"].GridColumnStyles[0].Width=0
;

MyDataGrid.TableStyles["DataTable_Berechtigung"].GridColumnStyles[1].Width=8
0;

MyDataGrid.TableStyles["DataTable_Berechtigung"].GridColumnStyles[2].Width=8
0;

MyDataGrid.TableStyles["DataTable_Berechtigung"].GridColumnStyles[3].Width=2
0;

// Zeilen erstellen und inhalt abfüllen

// checkbox in variable

int test = 1;

dt.Rows.Add(new Object[] {"Adresse", "ev. sondst noch was",0,test,0,0,0});

dt.Rows.Add(new Object[] {"Depositen", "ev. sondst noch was",1,1,1,1,1});

dt.Rows.Add(new Object[] {"Obligation", "ev. sondst noch was",0,0,0,0,0});

dt.Rows.Add(new Object[] {"Miete", "ev. sondst noch was",1,1,1,1,1});

dt.Rows.Add(new Object[] {"Stammdaten", "ev. sondst noch was",0,0,0,0,0});

// DataTable in dataset

MyDataSet.Tables.Add(dt);

// Dataset in datagrid

MyDataGrid.SetDataBinding(MyDataSet,"DataTable_Berechtigung");

// Anzeigen des Datagrids

this.Controls.Add(MyDataGrid);

}
 
F

Frans Bouma [C# MVP]

display checkbox in datagrid.

I find that there are 3 status:
checked - check box with click icon
unchecked - blank in check box
unknown - click icon but color in gray.....

How can I set the check box only 2 status, checked and unchecked?

Set in the datagridcolumn style the following properties:
- AllowNull to false
- NullValue to null
- FalseValue to false
- TrueValue to true

Frans.

ps: winforms faq: http://www.syncfusion.com/FAQ/WinForms/default.asp
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top