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

Hi, Is there a way to use a filter bar with GridDataBoundGrid when the datasource is IList ? Regards, Mikaël

11 Replies

AD Administrator Syncfusion Team February 24, 2005 05:31 PM UTC

No, it is not supported in our library. You would have to implement it yourself. The 3.0 GridGroupingControl has a filterbar that can be used with IList objects.


MM Mikaël Morvan March 2, 2005 12:42 PM UTC

How do I make the filter bar use textboxes and have the display respond to each keystroke with the GridGroupingControl ? How can i use an GridFilterBar inherit class (like GridTextBoxFilterBar) with GridGroupingControl ?


AD Administrator Syncfusion Team March 2, 2005 04:49 PM UTC

You will not be able to use a derived GridFilterBar class in GridGroupingControl. Try this. Handle these two events. this.groupingGrid1.QueryCellStyleInfo += new GridTableCellStyleInfoEventHandler(groupingGrid1_QueryCellStyleInfo); this.groupingGrid1.TableControlCurrentCellChanged += new GridTableControlEventHandler(groupingGrid1_TableControlCurrentCellChanged);
private void groupingGrid1_QueryCellStyleInfo(object sender, GridTableCellStyleInfoEventArgs e)
{
	if(e.TableCellIdentity.TableCellType == GridTableCellType.FilterBarCell)
	{
		e.Style.ShowButtons = GridShowButtons.Hide;
		e.Style.BackColor = Color.LightGoldenrodYellow;
		e.Style.DropDownStyle = GridDropDownStyle.Editable;
		e.Style.CellType = "TextBox";
	}
}

private void groupingGrid1_TableControlCurrentCellChanged(object sender, GridTableControlEventArgs e)
{
	GridCurrentCell cc = e.TableControl.CurrentCell;
	GridTableCellStyleInfo style = e.TableControl.Model[cc.RowIndex, cc.ColIndex] as GridTableCellStyleInfo;
	if (style.TableCellIdentity.TableCellType == GridTableCellType.FilterBarCell)
	{
		string s = string.Format("[{0}] LIKE ''{1}*''", style.TableCellIdentity.Column.MappingName, cc.Renderer.ControlText);
		this.groupingGrid1.TableDescriptor.RecordFilters.Clear();
		this.groupingGrid1.TableDescriptor.RecordFilters.Add(s);
	}
}



MM Mikaël Morvan March 10, 2005 05:34 PM UTC

Thanks, I''ve copied and paste the code you send. It seems to work well, but there is a strange behaviour that appears when I try to enter a filter in one of the textbox cell (after having selected a row in the grid) the textbox control lose his focus (after I had typed the first character) and one of the result rows is selected. This prevents me to type an entire filter. Do you have an explanation or workarround ? A sample project is attached in a zip file ( WindowsApplication3_9515.zip). Here is a scenario: 1- load the application 2- type something in the "ContactName" cell filter Everything is OK Now: 3- select one the result rows 4- type something in the "ContactName" cell filter 5- a row is selected after you had typed the first character ... Regards. Mikaël.


AD Administrator Syncfusion Team March 10, 2005 06:04 PM UTC

Try handling the TableControlCurrentCellMoving event.
private void gridGroupingControl1_TableControlCurrentCellMoving(object sender, GridTableControlCurrentCellMovingEventArgs e)
{
	GridCurrentCell cc = e.TableControl.CurrentCell;
	GridTableCellStyleInfo style = e.TableControl.Model[cc.MoveToRowIndex, cc.MoveToColIndex] as GridTableCellStyleInfo;
	if (style.TableCellIdentity.TableCellType == GridTableCellType.FilterBarCell)
	{
		this.gridGroupingControl1.Table.CurrentRecord = null;
	}
}


MM Mikaël Morvan May 26, 2005 10:51 AM UTC

This work fine until i install the 3.2.1.0 version. Do you have any ideas ? Thanks, Mikaël >Try handling the TableControlCurrentCellMoving event. >
>private void gridGroupingControl1_TableControlCurrentCellMoving(object sender, GridTableControlCurrentCellMovingEventArgs e)
>{
>	GridCurrentCell cc = e.TableControl.CurrentCell;
>	GridTableCellStyleInfo style = e.TableControl.Model[cc.MoveToRowIndex, cc.MoveToColIndex] as GridTableCellStyleInfo;
>	if (style.TableCellIdentity.TableCellType == GridTableCellType.FilterBarCell)
>	{
>		this.gridGroupingControl1.Table.CurrentRecord = null;
>	}
>}
>


AD Administrator Syncfusion Team May 26, 2005 01:39 PM UTC

Try switching the order of these two lines in gridGroupingControl1_TableControlCurrentCellChanged. string s1 = cc.Renderer.ControlText; this.gridGroupingControl1.TableDescriptor.RecordFilters.Clear(); //this.gridGroupingControl1.TableDescriptor.RecordFilters.Clear(); //string s1 = cc.Renderer.ControlText;


MM Mikaël Morvan May 27, 2005 03:16 PM UTC

Hi, The problem is that I can''t type more than one character in the textbox filter. The filter is immediatly applied and the filter cell lose his focus. So, I have to re-select the filter cell in order to go on typing my criteria. How can i prevent this behavior ? Regards. Mikaël


AD Administrator Syncfusion Team May 27, 2005 04:02 PM UTC

Try this handler.
private void gridGroupingControl1_TableControlCurrentCellChanged(object sender, GridTableControlEventArgs e)
{
	GridCurrentCell cc = e.TableControl.CurrentCell;
	GridTableCellStyleInfo style = e.TableControl.Model[cc.RowIndex, cc.ColIndex] as GridTableCellStyleInfo;
	if (style.TableCellIdentity.TableCellType == GridTableCellType.FilterBarCell)
	{
		string s1 = cc.Renderer.ControlText;
		if ((s1 != null) && (s1 != string.Empty)) 
		{
			string s = string.Format("[{0}] LIKE ''{1}*''", style.TableCellIdentity.Column.MappingName, s1);
			cc.Lock();
			if(this.gridGroupingControl1.TableDescriptor.RecordFilters.Count == 0)
				this.gridGroupingControl1.TableDescriptor.RecordFilters.Add(s);
			else
				this.gridGroupingControl1.TableDescriptor.RecordFilters[0].Expression = s;
			cc.Unlock();
		}
	}
}


BW Brian Wright May 27, 2005 06:52 PM UTC

Hi.. I hate to jump into this thread. But as luck would have it, I need to do exactly what you have described. Following your instructions, everything is working like a charm, except for one thing: When a filterbar TextBox loses focus, it no longer shows the filter they typed in. For example, if I type a ''br'' in a filterbar Textbox under a specific column, it filters great.. But as soon as I leave that cell in the filterbar, the ''br'' text disappears. The filter remains, just the text disappears, making it hard for the user to remember if he even has any filters active on the grid or not. Is there a way to prevent this? >Try this handler. >
>private void gridGroupingControl1_TableControlCurrentCellChanged(object sender, GridTableControlEventArgs e)
>{
>	GridCurrentCell cc = e.TableControl.CurrentCell;
>	GridTableCellStyleInfo style = e.TableControl.Model[cc.RowIndex, cc.ColIndex] as GridTableCellStyleInfo;
>	if (style.TableCellIdentity.TableCellType == GridTableCellType.FilterBarCell)
>	{
>		string s1 = cc.Renderer.ControlText;
>		if ((s1 != null) && (s1 != string.Empty)) 
>		{
>			string s = string.Format("[{0}] LIKE ''{1}*''", style.TableCellIdentity.Column.MappingName, s1);
>			cc.Lock();
>			if(this.gridGroupingControl1.TableDescriptor.RecordFilters.Count == 0)
>				this.gridGroupingControl1.TableDescriptor.RecordFilters.Add(s);
>			else
>				this.gridGroupingControl1.TableDescriptor.RecordFilters[0].Expression = s;
>			cc.Unlock();
>		}
>	}
>}
>


AD Administrator Syncfusion Team May 27, 2005 08:52 PM UTC

Add a Hashtable to hold these values, an dthen modify the two even handlers to save the values in teh hashtable and retrieve them from the hashtable.
private Hashtable saveValues = new Hashtable();

private void gridGroupingControl1_QueryCellStyleInfo(object sender, GridTableCellStyleInfoEventArgs e)
{
	if(e.TableCellIdentity.TableCellType == GridTableCellType.FilterBarCell)
	{
		e.Style.ShowButtons = GridShowButtons.Hide;
		e.Style.BackColor = Color.LightGoldenrodYellow;
		e.Style.DropDownStyle = GridDropDownStyle.Editable;
		e.Style.CellType = "TextBox";
		e.Style.CellValue = saveValues[e.Style.TableCellIdentity.Column];
	}
}


private void gridGroupingControl1_TableControlCurrentCellChanged(object sender, GridTableControlEventArgs e)
{
	GridCurrentCell cc = e.TableControl.CurrentCell;
	GridTableCellStyleInfo style = e.TableControl.Model[cc.RowIndex, cc.ColIndex] as GridTableCellStyleInfo;
	if (style.TableCellIdentity.TableCellType == GridTableCellType.FilterBarCell)
	{
		string s1 = cc.Renderer.ControlText;
		if ((s1 != null) && (s1 != string.Empty)) 
		{
			string s = string.Format("[{0}] LIKE ''{1}*''", style.TableCellIdentity.Column.MappingName, s1);
			cc.Lock();
			if(this.gridGroupingControl1.TableDescriptor.RecordFilters.Count == 0)
				this.gridGroupingControl1.TableDescriptor.RecordFilters.Add(s);
			else
				this.gridGroupingControl1.TableDescriptor.RecordFilters[0].Expression = s;
			if(saveValues.ContainsKey(style.TableCellIdentity.Column))
				saveValues[style.TableCellIdentity.Column] = s1;
			else
				saveValues.Add(style.TableCellIdentity.Column,s1);

			cc.Unlock();
		}
	}
}

Loader.
Live Chat Icon For mobile
Up arrow icon