I'm newbie on winform and datagrid

I have a DataGrid with a DataGridBoolColumn.
The DataGrid is binded to a DataTable.

The DataTable is the resultset of SQL query "SELECT UserName, Enabled FROM
siteuser" and the Enabled field is a integer type that 1 means enabled while
non-1 means disabled.

I want the DataGridBoolColumn is checked if the Enabled is 1 while keep
unchecked if it's not.

How can I do that? Here is my snippet:

DataGridTableStyle tableStyle = new DataGridTableStyle();
tableStyle.MappingName = "Siteuser";

DataGridTextBoxColumn textColumn = new DataGridTextBoxColumn();
textColumn.MappingName = "UserName";
textColumn.HeaderText = "User Name";
tableStyle.GridColumnStyles.Add(textColumn);

DataGridBoolColumn boolColumn = new DataGridBoolColumn();
boolColumn.MappingName = "Enabled";
boolColumn.HeaderText = "Enabled";
boolColumn.AllowNull = false;
tableStyle.GridColumnStyles.Add(boolColumn);

this.dataGrid1.TableStyles.Add(tableStyle);

this.dataGrid1.DataSource = dataTable;

Re: Databinding on DataGridBoolColumn by Marc

Marc
Wed Mar 01 03:24:25 CST 2006

Well, have you tried changing the SQL to return a bit? i.e. CAST(CASE
Enabled WHEN 1 THEN 1 ELSE 0 END as bit)

?

Marc



Re: Databinding on DataGridBoolColumn by JasonChan

JasonChan
Wed Mar 01 03:58:27 CST 2006

Thanks Marc,

I solved my problem!

My I got another issue:

The checkbox in the DataGridBoolColumn has 3 states!
Beside from checked and unchecked, it have another state that have a tick in
a grey checkbox (look like disabled checkbox)
It changes states from "checked" -> "grey checked" -> "unchecked"

How can I disable the grey checkbox, I already set
DataGridBoolColumn.AllowNull to false

Re: Databinding on DataGridBoolColumn by Marc

Marc
Wed Mar 01 04:17:53 CST 2006

Try setting .ThreeState to false on the column

Marc



Re: Databinding on DataGridBoolColumn by Dougman

Dougman
Thu Apr 20 17:38:01 CDT 2006

I am having the same headache. Where is this ".ThreeState" property? I can't
find it either in DataGridBoolColumn or DataColumn. It can be found in
CheckBox, but that is no help as there is no access to the hosted control
from DataGridBoolColumn as there is in DataGridTextBoxColumn.

"Marc Gravell" wrote:

> Try setting .ThreeState to false on the column
>
> Marc