Displaying bool as a Checkbox in a DataGrid

J

jdipalmajr

I have a table which is being displayed in a DataGrid. One of the
columns is a boolean. When I began my development, I wasn't using
styles to control column formats. When I used the default styles, the
boolean displayed as a checkbox (checked if true and unchecked if
false). Now that I am using styles to control for format of my
DataGrid columns, the boolean displays as the words "true" and "false".

Does anyone know how to define a column style so that boolean's will
display as a checkbox in the DataGrid form?

Jerry
 
M

Maqsood Ahmed

Hello,
Use DataGridBoolColumn instead of DataGridTextBoxColumn for the
boolean column. If you are designing Styles from IDE, there is a
dropdown on "Add" button from where you select either TextBoxColumn or
BoolColumn. By default it adds TextBoxColumn.

HTH. Cheers :)
Maqsood Ahmed [MCP,C#]
Kolachi Advanced Technologies
http://www.kolachi.net
 
C

ClayB [Syncfusion]

If this is a Windows Forms DataGrid, when you add your columnstyles to the
DataGridTableStyle, are you adding a DataGridBoolColumn instead of a
DataGridColumnStyle or DataGridTextBoxColumn?

=================
Clay Burch, .NET MVP

Visit www.syncfusion.com for the coolest tools
 
J

jdipalmajr

That was the answer I was looking for. I would never have seen the
button dropdown on the add if you hadn't pointed it out. Thanks! I
have one other follow up question. The datagrid displays the boolean
as a checkbox. If I click the checkbox, the boolean changes from a
clear box to a solid checkmark. However, if I click the box again, I
get a grey box. One more click produces a clear box again. What is
the greyed checkbox? Shouldn't the value either be true or false?
 
C

ClayB [Syncfusion]

In your DataGridBoolColumn object, try setting the AllowNull property to
false.

DataGridBoolColumn boolCol =
this.dataGrid1.TableStyles["ArrayList"].GridColumnStyles["Image"] as
DataGridBoolColumn;
boolCol.AllowNull = false;

==================
Clay Burch, .NET MVP

Visit www.syncfusion.com for the coolest tools
 
J

jdipalmajr

Thanks very much! That was the answer I needed. Just like the drop
down button to setup a Boolean column, I doubt I would have found the
AllowNull = false solution either.

Thanks again.

Jerry
 

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