473,408 Members | 2,888 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,408 software developers and data experts.

display checkbox in datagrid.

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_Ber echtigung");

// Anzeigen des Datagrids

this.Controls.Add(MyDataGrid);

}
Nov 16 '05 #1
2 2755
"michael walser" <mi************@bingo.de> wrote in
news:uF**************@tk2msftngp13.phx.gbl:
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
--
Get LLBLGen Pro, the new O/R mapper for .NET: http://www.llblgen.com
My .NET Blog: http://weblogs.asp.net/fbouma
Microsoft C# MVP
Nov 16 '05 #2
yes it works

thanks for your help

michael
Nov 16 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: michael walser | last post by:
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...
0
by: Just D | last post by:
Hi All, Does anybody know how to write the following code? I have a database table with a few columns including: ID , "Task" , ForceRun . I need to show the DataGrid on the ASPX page with...
2
by: Sebi | last post by:
Hello all is it possible to add a checkbox in a DataGrid for Boolean Data? Thanks in advance
0
by: mike | last post by:
Hi there: I've read an excellent "how to"-article by Microsoft (no. 306227) - partly cited cited at the end of this email). I have implemented the code related to the part "How to Add a...
1
by: iforsyth | last post by:
Have a paging datagrid with a checkbox control in column(0). ViewState is enabled. I check the checkbox in first row of the grid on a page and then the program hits this event: Private Sub...
0
by: mehul | last post by:
CheckBox template always evaluate to False even if checked in a DataGrid hosted inside a TabStrip in ASP.NET Hi, I am trying to develop an ASP.NET application. I am using TabStrip (which is...
7
by: Lars Netzel | last post by:
If I put a checkbox in a datagrid (ASP.NET) and set the Autopostback to true I can catch OnChange event on checkbox but how do I then catch what DataGridItemIndex is? Can I use some Event in the...
2
by: Adam Knight | last post by:
Hi all, I have a datagrid with a checkbox in one column. The checkbox is set to autopostback and calls a method named UpdateMailSubscribers. The first click on the checkbox cause the page to...
9
by: Rekha | last post by:
The data is filled in datagrid. I want to know how to add a checkbox column in datagrid? In the runtime, checkbox is checked then instead of checkbox value the (caseID )column value is retained....
3
by: Fao, Sean | last post by:
I have a DataGrid that I'm adding CheckBox controls to at runtime (in the code behind) and I'm not sure if I'm doing it correctly. First of all, I noticed that the MyDataGrid.Columns.Add() method...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.