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

Checkbox state change

Hi,

I am using syncfusion gridcontrol in which one column is checkbox. There is CheckboxClick event. But it is not coming for when we check checkbox by space key.  We can use currentcellchanged but it rises for all column change. Is there any event specific to gridcontrolcheckboxstate change ? I am using Syncfusion.Windows.Forms.Grid.GridControl.

Regards,
BJ

3 Replies

NK Neelakandan Kannan Syncfusion Team November 13, 2014 11:06 AM UTC

Hi Santhosh,

 

Thank you for your interest in Syncfusion products.

 

If you want to detect the check box state, you need to assign its state by using CheckBoxOptions property. And you can get check box state by using its CellValue. Please make use of below code,

 

this.gridControl1.ColStyles[1].CellType = GridCellTypeName.CheckBox;

this.gridControl1.ColStyles[1].CheckBoxOptions = new GridCheckBoxCellInfo("true", "false", "", true);

this.gridControl1.ColStyles[1].CellValue = true;

 

this.gridControl1.CheckBoxClick += new GridCellClickEventHandler(gridControl1_CheckBoxClick);

void gridControl1_CheckBoxClick(object sender, GridCellClickEventArgs e)

{

if(this.gridControl1[e.RowIndex,e.ColIndex].CellValue=="true")

MessageBoxAdv.Show("Checked state");

else

MessageBoxAdv.Show("UnChecked state");

}

 

Please let me know if you have any concerns.

 

Regards,

Neelakandan



SB Santhosh BJ November 13, 2014 11:55 AM UTC

Will it work for the scenario where checkbox is checked by using spacebar key ?


Regards,
Santhosh BJ


NK Neelakandan Kannan Syncfusion Team November 17, 2014 04:37 AM UTC

Hi Santhosh,

 

Thank you for your update.

 

If you want to change the check box state using SpaceBar key, you can use CurrentCellKeyDown event to customize your scenario. Please make use of below code and attached sample,

 

this.gridControl1.CurrentCellKeyDown += new KeyEventHandler(gridControl1_CurrentCellKeyDown);

 

void gridControl1_CurrentCellKeyDown(object sender, KeyEventArgs e)

{

if (e.KeyCode == Keys.Space)

{

if (this.gridControl1[this.gridControl1.CurrentCell.RowIndex, this.gridControl1.CurrentCell.ColIndex].CellType == GridCellTypeName.CheckBox)

{

if (this.gridControl1[this.gridControl1.CurrentCell.RowIndex, this.gridControl1.CurrentCell.ColIndex].CellValue == true.ToString())

{

this.gridControl1[this.gridControl1.CurrentCell.RowIndex, this.gridControl1.CurrentCell.ColIndex].CellValue = false;

}

else if (this.gridControl1[this.gridControl1.CurrentCell.RowIndex, this.gridControl1.CurrentCell.ColIndex].CellValue==false.ToString())

this.gridControl1[this.gridControl1.CurrentCell.RowIndex, this.gridControl1.CurrentCell.ColIndex].CellValue = true;

}

}

}

 

Please let me know if you have any concerns.

 

Regards,

Neelakandan


Attachment: Sample_CheckBox_Demo_613d91d6.zip

Loader.
Live Chat Icon For mobile
Up arrow icon