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

FilterBar for CheckBox type column

Hi, I have a databound grid with one column with CHECKBOX style. Data is 1 and 0. If 1, the cell is checked and if 0 it is unchecked. It is working properly. I need to display "Yes" and "No" as my filter options in my filterbar for the column. Is there any option for doing this. Any help in this regard is really appreciated. Thanks in advance, Bidin

2 Replies

AD Administrator Syncfusion Team August 10, 2004 01:40 AM

There are no property setting that will do this for you. You can handle the CurrrentCellShowingDropDown event. You can swap out the datasource for the dropdown at that point. In the new datasource, you would have a display member column showing yes/no and a Value member column returning the 1 and 0 that is used by your normal column. Here is a rough snippet. (Did not actually try this, so don''t know if you will have to change the typeof(int) to something else that better matches the type of the actual column you are using. (Mayen string, maybe bool).
private void gridDataBoundGrid1_CurrentCellShowingDropDown(object sender, GridCurrentCellShowingDropDownEventArgs e)
{
	GridCurrentCell cc = this.gridDataBoundGrid.CurrentCell;
	if(cc.ColIndex == 2 && cc.RowIndex == 1)
 	{
		GridComboBoxCellRenderer cr = cc.Renderer as GridComboBoxCellRenderer;
		if(cr != null)
		{
			DataTable dt = new DataTable("YesNo");
			dt.Columns.Add(new DataColumn("id", typeof(int)));
			dt.Columns.Add(new DataColumn("display");
			DataRow dr =dt.NewRow();
			dr[0] = 1;
			dr[1] = "Yes";
			dt.Rows.Add(dr);
			dr =dt.NewRow();
			dr[0] = 0;
			dr[1] = "No";
			dt.Rows.Add(dr);
			((GridComboBoxListBoxPart)cr.ListBoxPart).DataSource = dv;
			((GridComboBoxListBoxPart)cr.ListBoxPart).DisplayMember = "display";
			((GridComboBoxListBoxPart)cr.ListBoxPart).ValueMember = "id";
		}
	}
}


BD Bidin Dinesababu August 10, 2004 01:24 PM

Thanks for the quick response. I could make it work with the following code. //Modify stules grid.Model.ColStyles["column5"].CellType = "CheckBox"; grid.Model.ColStyles["column5"].CheckBoxOptions.CheckedValue = "Yes"; this.Model.ColStyles["column5"].CheckBoxOptions.UncheckedValue = "No"; And populating the column values as "Yes" for 1 and "No" for 0.

Loader.
Live Chat Icon For mobile
Up arrow icon