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. (Last updated on: November 16, 2018).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

GDBG and a column of mutually exclusive checkboxes

Thread ID:

Created:

Updated:

Platform:

Replies:

50789 Oct 19,2006 12:34 AM UTC Oct 20,2006 02:01 AM UTC WinForms 2
loading
Tags: GridControl
Albert
Asked On October 19, 2006 12:34 AM UTC

I have a WinForm grid with one of the columns of Checkbox type.
How can I make sure that only one checkbox can be in the Checked state at any given time ?

I've tried the code below

private void gridDataBoundGrid1_CurrentCellChanged(object sender, System.EventArgs e)
{
GridCurrentCell cc = gridDataBoundGrid1.CurrentCell;
if ( (bool)cc.Renderer.StyleInfo.CellValue == false )
return;

for(int i = 1; i <= gridDataBoundGrid1.Model.RowCount; i++)
{

if ( i != cc.RowIndex )
gridDataBoundGrid1.Model[i, cc.ColIndex].CellValue = false;
}
}

but that resets all checkboxes to false.

Can anyone advise an alternative solution or why my code above is not working.
Your help is greatly appreciated.

Administrator [Syncfusion]
Replied On October 19, 2006 09:56 AM UTC

Hi Albert,

Please try the code below in the CurrentCellChanged event handler of the grid, to have mutually exclusive checkboxes in a checkbox column.

private void gridDataBoundGrid1_CurrentCellChanged(object sender, EventArgs e)
{
GridCurrentCell cc = this.gridDataBoundGrid1.CurrentCell;
if(cc.Renderer.StyleInfo.CellType == "CheckBox")
{
bool check = (bool)cc.Renderer.StyleInfo.CellValue;
for(int i = 1; i <= this.gridDataBoundGrid1.Model.RowCount; i++)
{
if(check)
this.gridDataBoundGrid1.Model[i, cc.ColIndex].CellValue = false;
}
this.gridDataBoundGrid1.Model[cc.RowIndex, cc.ColIndex].CellValue = true;
}
}

Let me know if this helps.
Regards,
Rajagopal

Albert
Replied On October 20, 2006 02:01 AM UTC

Thanks, Rajagopal.

It works apart from one of the requirements that I forgot to mention in my first post. It is allowed to have all checkboxes in the column to be unchecked, but only one of them can be checked.

Regards,
Albert

>Hi Albert,

Please try the code below in the CurrentCellChanged event handler of the grid, to have mutually exclusive checkboxes in a checkbox column.

private void gridDataBoundGrid1_CurrentCellChanged(object sender, EventArgs e)
{
GridCurrentCell cc = this.gridDataBoundGrid1.CurrentCell;
if(cc.Renderer.StyleInfo.CellType == "CheckBox")
{
bool check = (bool)cc.Renderer.StyleInfo.CellValue;
for(int i = 1; i <= this.gridDataBoundGrid1.Model.RowCount; i++)
{
if(check)
this.gridDataBoundGrid1.Model[i, cc.ColIndex].CellValue = false;
}
this.gridDataBoundGrid1.Model[cc.RowIndex, cc.ColIndex].CellValue = true;
}
}

Let me know if this helps.
Regards,
Rajagopal

CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon

;