CheckBox in DataGrid

  • Thread starter Thread starter Jon Yates
  • Start date Start date
J

Jon Yates

Hello all.

I have place a CheckBox in a DataGrid using the following
code:

DataColumn dcInclude = new DataColumn("Include?");
dcInclude.DataType = System.Type.GetType
("System.Boolean");
dtParams.Columns.Add(dcInclude);

The CheckBox column works and all is good, however, the
CheckBox has 3 states. Ticked, un-ticked and grey ticked.

Is it possible to have it so that the CheckBox only has 2
states (Ticked and un-ticked)?

Thanks people,

Jon
 
Ok I'm assuming you are not creating the table sytle your
self but rather you are depending on the auto create table
style??

if autocreate then change the column's allow null to false

if tablestyle then change the columnstyle checkbox to
allow Null = false

Hope this helps.

Joe
 
Hello Joe. Thanks for your reply.

This didn't work as I'm creating a new DataColumn and
adding it to the DataTable.

However, if found this code and it works great. Thanks
though.

private void dataGrid1_MouseUp(object sender,
System.Windows.Forms.MouseEventArgs e)
{
DataGrid.HitTestInfo hti = this.dataGrid1.HitTest
(e.X, e.Y);
try
{
if( hti.Type == DataGrid.HitTestType.Cell &&
hti.Column == 23 || hti.Column == 25)
{
this.dataGrid1[hti.Row, hti.Column] = ! (bool)
this.dataGrid1[hti.Row, hti.Column];
}
}

catch(Exception ex)
{
MessageBox.Show(ex.ToString());
}
}
 
Back
Top