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.
Unfortunately, activation email could not send to your email. Please try again.

GDBG and a column of mutually exclusive checkboxes

Thread ID:

Created:

Updated:

Platform:

Replies:

50789 Oct 18,2006 08:34 PM Oct 19,2006 10:01 PM Windows Forms 2
loading
Tags: GridControl
Albert
Asked On October 18, 2006 08:34 PM

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 05:56 AM

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 19, 2006 10:01 PM

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.

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.

;