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. Image for the cookie policy date

Using a DataGridBoolColumn in a DataGrid

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.

6 Replies

IF Ilse Frans 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.


CH Chris 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 !)


AD Administrator Syncfusion Team 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.


AD Administrator Syncfusion Team 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!


NA natella2317 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 !)
>


VI vishnu 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

Loader.
Live Chat Icon For mobile
Up arrow icon