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.
Syncfusion Feedback

FilterBar questions

Thread ID:

Created:

Updated:

Platform:

Replies:

57626 Mar 7,2007 02:53 PM UTC Mar 9,2007 06:50 PM UTC Windows Forms 5
loading
Tags: GridControl
Srdjan
Asked On March 7, 2007 02:53 PM UTC

Hi

1. In my example Currency FilterBar displays values from value column instead od display column. Can you show me what to do?

2. How can I implement incremental search on Country column. Something like autocomplete search. If I type 'F' key I would like to get all rows where Country begins with an F and so on. In FilterBar row ofcourse.

Thanks in advance.

ExampleGrid0.zip

Administrator [Syncfusion]
Replied On March 7, 2007 06:05 PM UTC

Hi Srdjan,

Issue 1:
You can handle the ListBoxPart.DrawItem event and draw the substituted values to the dropdown listbox control. Before handling the DrawItem event, you should set the ListBoxPart.DrawMode property to DrawMode.OwnerDrawFixed in TableControlCurrentCellShowingDropDown event. Here is a sample code snippet.

int savedIndex = -1;
string SelectedText = string.Empty;
private void ListBoxPart_DrawItem(object sender, DrawItemEventArgs e)
{
//Declare the SavedIndex as the Class Member.....


ListBox list = sender as ListBox;
StringFormat format = new StringFormat();
format.LineAlignment = StringAlignment.Center;
format.Alignment = StringAlignment.Center;

RectangleF rect = new RectangleF(e.Bounds.X, e.Bounds.Y, e.Bounds.Width, e.Bounds.Height);

///// dText is the drawing text of the DropDown listBox
//// dText is the DisplayText of the DropDown listBox
//// you can assign any of the text to dText here
////--------------------------------------------------------------------------------------------------------////
string dText = list.Items[e.Index].ToString();
if (e.Index > 2)
dText = currency.Rows[e.Index - 3]["Currency"].ToString();
////--------------------------------------------------------------------------------------------------------////

if (list.SelectedIndex == e.Index)
{
if (savedIndex != -1 && savedIndex != list.SelectedIndex)
list.Invalidate(list.GetItemRectangle(savedIndex));
savedIndex = list.SelectedIndex;
e.Graphics.FillRectangle(Brushes.Gold, e.Bounds);
e.Graphics.DrawString(dText, list.Font, new SolidBrush(list.BackColor), rect, format);
SelectedText = dText;
}
else
{
e.Graphics.FillRectangle(Brushes.LightGoldenrodYellow, e.Bounds);
e.Graphics.DrawString(dText, list.Font, new SolidBrush(list.ForeColor), rect, format);
}
}

Issue 2:

One way you can do this by handling the QueryCellInfo event to set the CellType to "TextBox" in a filterbar cell and also you can handle the TableControlCurrentCellKeyPress event for adding the RecordFilters in a grid.

Modified sample : ExampleGrid0.zip

Best regards,
Haneef

Srdjan
Replied On March 8, 2007 12:43 PM UTC

Thanks for the effort I appreciate it.

However gridGroupingControl1_TableControlCurrentCellKeyPress event is not complete, it has syntax errors. Can you give me snippet to complete event code?

Thanks.




Administrator [Syncfusion]
Replied On March 8, 2007 08:46 PM UTC

Hi Srdjan,

You can handle the TableControlCurrentCellChanged event of the grid and add the RecordFilter to the GridTableDescriptor. Please try the below code snippet and let me know if this helps.

void gridGroupingControl1_TableControlCurrentCellChanged(object sender, GridTableControlEventArgs e)
{
GridCurrentCell cc = e.TableControl.CurrentCell;
GridTextBoxCellRenderer cr = cc.Renderer as GridTextBoxCellRenderer;
if (cr != null)
{
GridTableCellStyleInfo style = cr.CurrentStyle as GridTableCellStyleInfo;
if (style.TableCellIdentity.DisplayElement.Kind == DisplayElementKind.FilterBar
&& style.CellType == "TextBox")
{
int RowIndex = cc.RowIndex;
int ColIndex = cc.ColIndex;
object getEditState = cr.GetEditState();
TextFilterText = cr.ControlText;
GridTableDescriptor td = e.TableControl.TableDescriptor;
string name = td.VisibleColumns[td.ColIndexToField(cc.ColIndex)].Name;
td.RecordFilters.Remove(name);
FilterCondition condition = new FilterCondition(FilterCompareOperator.Like, cr.ControlText + "*");
RecordFilterDescriptor rfd = new RecordFilterDescriptor(name, condition);
td.RecordFilters.Add(rfd);
cc.MoveTo(RowIndex, ColIndex);
cc.BeginEdit();
cr.SetEditState(getEditState);
}
}
}

Best regards,
Haneef

Srdjan
Replied On March 9, 2007 01:53 PM UTC

Your sample worked nicely and this is what I wanted. Excellent.

A minor annoyance though: If I leave FilterBar cell, for example if I click on another FilterBar cell, entered text is cleared altough the filtering is still present.

What can I do so that entered text is persisted until user determines that filter is no longer needed and deletes it?

Also I cannot use Tab and Arrow keys on filterbar row. Any suggestion with that?

Thanks in advance.

Administrator [Syncfusion]
Replied On March 9, 2007 06:50 PM UTC

Hi Srdjan,

Regarding 1 :

If I leave FilterBar cell, for example if I click on another FilterBar cell, entered text is cleared altough the filtering is still present.
>>>>>
You can handle the TableControlCurrentCellEditingComplete event of the grid and remove filter using the RecordFilters.Remove method.

void gridGroupingControl1_TableControlCurrentCellEditingComplete(object sender, GridTableControlEventArgs e)
{
GridCurrentCell cc = e.TableControl.CurrentCell;
GridTextBoxCellRenderer cr = cc.Renderer as GridTextBoxCellRenderer;
if (cr != null)
{
GridTableCellStyleInfo style = cr.CurrentStyle as GridTableCellStyleInfo;
if (style.TableCellIdentity.DisplayElement.Kind == DisplayElementKind.FilterBar
&& style.CellType == "TextBox")
{
int RowIndex = cc.RowIndex;
int ColIndex = cc.ColIndex;
GridTableDescriptor td = e.TableControl.TableDescriptor;
string name = td.VisibleColumns[td.ColIndexToField(cc.ColIndex)].Name;
td.RecordFilters.Remove(name);
}
}
}


Regarding 2 :
Also I cannot use Tab and Arrow keys on filterbar row. Any suggestion with that?
>>>>>
You catch the TableControlCurrentCellKeyDown event and set the e.Inner.Handled to TRUE when The Tab and Arrow are pressed in the filter row.

void gridGroupingControl1_TableControlCurrentCellKeyDown(object sender, GridTableControlKeyEventArgs e)
{

GridCurrentCell cc = e.TableControl.CurrentCell;
GridTextBoxCellRenderer cr = cc.Renderer as GridTextBoxCellRenderer;
if (cr != null)
{
GridTableCellStyleInfo style = cr.CurrentStyle as GridTableCellStyleInfo;
if (style.TableCellIdentity.DisplayElement.Kind == DisplayElementKind.FilterBar
&& style.CellType == "TextBox")
{
e.Inner.Handled = true;
}
}
}

Best regards,
Haneef

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.

Warning Icon 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.Close Icon

;