databoundGrid column Toggle button

Hi.
I need to have the cells of a column to be displayed as toggle buttons. The cells display a boolean value, so i want to have the button pressed for true and not pressed for false.

Does anybody knows how can i do this?

Thanks
Stelios Halkiotis

1 Reply

AD Administrator Syncfusion Team September 15, 2006 09:31 AM UTC

Hi Stelios,

You would have to derive the GridStaticCellRenderer and override these methods.

protected override void OnDraw(Graphics g, Rectangle clientRectangle, int rowIndex, int colIndex, GridStyleInfo style)
{
bool b = false;
ButtonState state = ButtonState.Pushed;
if( style.CellValue != null && style.CellValueType == typeof(bool))
{
b = (bool) style.CellValue ;
if(b)
{
state = ButtonState.Normal;
}
}
ControlPaint.DrawButton(g,clientRectangle,state);
}

protected override void OnClick(int rowIndex, int colIndex, MouseEventArgs e)
{
base.OnClick (rowIndex, colIndex, e);
bool b = (bool)this.Grid.Model[rowIndex,colIndex].CellValue;
this.Grid.Model[rowIndex,colIndex].CellValue =!b;
this.Grid.RefreshRange(GridRangeInfo.Cell( rowIndex,colIndex));
}

Here is a sample.
http://www.syncfusion.com/Support/user/uploads/ToggleButtonCell_12ad16e3.zip

Let me know if this helps.

Thanks,
Haneef

Loader.
Up arrow icon