We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy.
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

Using a DataGridBoolColumn in a DataGrid

Thread ID:

Created:

Updated:

Platform:

Replies:

1450 Oct 30,2002 06:01 PM UTC May 5,2007 11:36 AM UTC Windows Forms 6
loading
Tags: FAQ
Thomas
Asked On October 30, 2002 06:01 PM UTC

Hello, First off, just want to say what a great resource this site is! Question: I have a DataGrid bound to a DataSet. The DataSet has the following columns and values: ID FirstName Lastname PWD string string string 0 string string string 1 string string string 0 etc. I've created a TableStyle object and created the DataGrid such that only whole rows are selected (not individual cells). The DataGrid consists of four columns with three DataGridTextColumns and one DataGridBoolColumn. When the DataGrid is displayed, the first three columns look fine. However, the DataGridBoolColumn does not look like it's actually reading any of the values from the DataSet, as all the boxes have a check mark and are grayed out, as if disabled. How do I 'enable' them so that they reflect the true value in that fourth column? Thanks.

Ilse Frans
Replied On October 31, 2002 12:37 PM UTC

Hello Thomas, The default BoolColumn can have 3 values, True, False and Null. Null is displayed as gray-out. To avoid the gray-out, you can add the following code: theColumn.AllowNull = False This way only two values are possible. Now you can indicate which value in the datatable represents true, and which represents false. For example: theColumn2.TrueValue = 0 theColumn2.FalseValue = 1 I hope this will to the trick, Ilse Frans > Hello, > First off, just want to say what a great resource this site is! > > Question: > I have a DataGrid bound to a DataSet. The DataSet has the following columns and values: > ID FirstName Lastname PWD > string string string 0 > string string string 1 > string string string 0 > etc. > > I've created a TableStyle object and created the DataGrid such that only whole rows are selected (not individual cells). > The DataGrid consists of four columns with three DataGridTextColumns and one DataGridBoolColumn. > When the DataGrid is displayed, the first three columns look fine. However, the DataGridBoolColumn does not look like it's actually reading any of the values from the DataSet, as all the boxes have a check mark and are grayed out, as if disabled. > How do I 'enable' them so that they reflect the true value in that fourth column? > > Thanks.

Chris
Replied On May 21, 2003 12:28 PM UTC

You *MUST* cast the TrueValue / FalseValue parameters to the correct type to prevent the Null (greyed) box appearing. You should be able to use anything as the value for the params as both take a type of "object". eg "Y", "N", 1, 0, -1(for VB6ers ;-) etc etc Just make sure you cast the type so that it matches your datasource e.g. say you return a DB field of type smallint where 2=true and 1=false and bind it to the bool column in your grid you would need the following : boolCol.TrueValue=(short)2; boolCol.FalseValue=(short)1; If you tried casting to (int) you'll get a grey box. This is v.poorly documented by Msft (in fact I can't find any docs at all !)

Administrator [Syncfusion]
Replied On December 12, 2003 12:07 AM UTC

> Hello Thomas, > > The default BoolColumn can have 3 values, True, False and Null. Null is displayed as gray-out. To avoid the gray-out, you can add the following code: > > theColumn.AllowNull = False > > This way only two values are possible. Now you can indicate which value in the datatable represents true, and which represents false. > For example: > > theColumn2.TrueValue = 0 > theColumn2.FalseValue = 1 > > I hope this will to the trick, > Ilse Frans > > > Hello, > > First off, just want to say what a great resource this site is! > > > > Question: > > I have a DataGrid bound to a DataSet. The DataSet has the following columns and values: > > ID FirstName Lastname PWD > > string string string 0 > > string string string 1 > > string string string 0 > > etc. > > > > I've created a TableStyle object and created the DataGrid such that only whole rows are selected (not individual cells). > > The DataGrid consists of four columns with three DataGridTextColumns and one DataGridBoolColumn. > > When the DataGrid is displayed, the first three columns look fine. However, the DataGridBoolColumn does not look like it's actually reading any of the values from the DataSet, as all the boxes have a check mark and are grayed out, as if disabled. > > How do I 'enable' them so that they reflect the true value in that fourth column? > > > > Thanks.

Administrator [Syncfusion]
Replied On April 19, 2004 03:04 PM UTC

Thank you so much for your "If you tried casting to (int) you'll get a grey box.". I almost die in this puddle. Love you!

natella2317
Replied On March 16, 2007 04:25 PM UTC

Chris,

I searched everywhere with no luck until I saw your post. It actually works now!
Thanks so much.

I would also like to note that if your data source is a MySQL database and your boolean column is of type BIT or TINYINT, then you must cast the TrueValue and FalseValue members to type Short:

[VB .Net]
boolCol.TrueValue = CShort(1) 'In MySQL 1=True
boolCol.FalseValue = CShort(0) 'In MySQL 0=False

[C#]
>boolCol.TrueValue=(short)1; 'In MySQL 1=True
>boolCol.FalseValue=(short)0; 'In MySQL 0=False


>You *MUST* cast the TrueValue / FalseValue parameters to the correct type to prevent the Null (greyed) box appearing. You should be able to use anything as the value for the params as both take a type of "object". eg "Y", "N", 1, 0, -1(for VB6ers ;-) etc etc
>
>Just make sure you cast the type so that it matches your datasource e.g. say you return a DB field of type smallint where 2=true and 1=false and bind it to the bool column in your grid you would need the following :
>
>boolCol.TrueValue=(short)2;
>boolCol.FalseValue=(short)1;
>
>If you tried casting to (int) you'll get a grey box.
>
>This is v.poorly documented by Msft (in fact I can't find any docs at all !)
>

vishnu
Replied On May 5, 2007 11:36 AM UTC

hi anyone help me how to save the checkbox values to database(postgresql) ie., i hv used the function
Dim col10 As New DataGridBoolColumn()
With col10
.MappingName = "delivery"
.HeaderText = "Delivery"
.Width = 70
.ReadOnly = False
End With
ts.GridColumnStyles.Add(col10)
DataGrid1.TableStyles.Add(ts)
DataGrid1.DataSource = DV

The thing is i hv to save the records which should be checked. The unchecked column i no need to save i should do this process
can anybody give me solution

CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon

;