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

How do i add checkbox header cell

Hi, I am using a GridDataBoundGrid. I have a bool column. I made the celltype of the bound column as "CheckBox". Instead of displaying a button, I want to display a checkbox in the header cell. When ever the user checks/unchecks the header checkbox, I want to toggle all checkboxes in the column. I tried setting gridDataBoundGrid1[0, 1].CellType = "CheckBox"; But I am still getting a header button instead of checkbox. What am I doing wrong? thanks, - Reddy

3 Replies

AD Administrator Syncfusion Team January 17, 2003 11:07 PM UTC

In a GridDataBoundGrid, you cannot use an indexer to set individual cell style properties (other than Text). The reason is that there is no data object allocated to save these properties. The only cell data is the data from your DataSource (this is why you can set the Text property as it is mapped to the data in your datasource, but you cannot set other cell properties.) So, to do something like this, you can use the Model.QueryCellInfo to set these properties, and then handle the grid's click event to toggle the setting. Attached is a rough try at this.


AD Administrator Syncfusion Team January 20, 2003 02:40 PM UTC

Clay, Thank you very much for your help. There is one problem with the sample. When I double click on the checkbox header, it is sorting the column. After that, when I try to click on header checkbox, it is not working properly. It is sorting the column dynamically. SortBehaviour is for the whole grid. Can I disable sorting for just one column? thanks, - Reddy


AD Administrator Syncfusion Team January 20, 2003 07:10 PM UTC

If you derive the GridDataBoundGrid, you can override OnCellDoubleClick and avoid the sort at that point.
public class MyGridDataBoundGrid : GridDataBoundGrid
{
	protected override void OnCellDoubleClick(GridCellClickEventArgs e)
	{
		if(e.ColIndex == 3 && e.RowIndex == 0)
			return;
		base.OnCellDoubleClick(e);
	}
}

Loader.
Live Chat Icon For mobile
Up arrow icon