I looked thru the forum but could find an example of what I need to do. And that is
empty the filter popup and populate it with my own entries.
For simplicity I only need 3 fields. The underlying column will contain only "A", "B", or blank/null so I would like the popup
to contain only those values. Even if the column could contain "C" or "D", I don't want to filter on that.
I know this can't be too difficult but I was unable to find an example and the code I wrote didn't work properly.
Any help appreciated.
Regards,
Hugo
5 Answers, 1 is accepted
Thx,
Hugo
Thank you for writing.
The FilterPopupInitialized event can be used for both, to remove any items you want and to change the items in the treeview:
void
radGridView1_FilterPopupInitialized(
object
sender, Telerik.WinControls.UI.FilterPopupInitializedEventArgs e)
{
RadListFilterPopup popup = e.FilterPopup
as
RadListFilterPopup;
if
(popup !=
null
)
{
popup.MenuElement.Items.RemoveAt(0);
popup.MenuElement.Items.RemoveAt(0);
popup.MenuTreeElement.DistinctListValues.Add(
"<empty>"
,
""
);
popup.MenuTreeElement.DistinctListValues.Remove(
"C"
);
popup.MenuTreeElement.DistinctListValues.Remove(
"D"
);
}
}
Please let me know if there is something else I can help you with.
Dimitar
Telerik
Hugo
Hi Dimitar,
I know that this is an old issue, but I am trying the same thing now, and I have been able to use this technique to add values to the filter popup menu tree element distinct list, but when I try to filter on those elements, I get no value passed. Do I need to do something to get the filter to work for these added list values?
Thanks,
Alec
Following the provided code snippet, I have prepared a sample project to test the behavior on my end with the latest version. You can find below the default filter popup:
After handling the FilterPopupInitialized event, the below result is accomplished:
public RadForm1()
{
InitializeComponent();
this.radGridView1.Columns.Add("Name");
this.radGridView1.AutoSizeColumnsMode = GridViewAutoSizeColumnsMode.Fill;
this.radGridView1.Rows.Add("A");
this.radGridView1.Rows.Add("B");
this.radGridView1.Rows.Add("C");
this.radGridView1.Rows.Add("D");
this.radGridView1.EnableFiltering = true;
this.radGridView1.ShowHeaderCellButtons = true;
this.radGridView1.ShowFilteringRow = false;
this.radGridView1.FilterPopupInitialized+=radGridView1_FilterPopupInitialized;
}
private void radGridView1_FilterPopupInitialized(object sender, FilterPopupInitializedEventArgs e)
{
RadListFilterPopup popup = e.FilterPopup as RadListFilterPopup;
if (popup != null)
{
popup.MenuElement.Items.RemoveAt(0);
popup.MenuElement.Items.RemoveAt(0);
popup.MenuTreeElement.DistinctListValues.Add("<empty>", "");
popup.MenuTreeElement.DistinctListValues.Remove("C");
popup.MenuTreeElement.DistinctListValues.Remove("D");
}
}
If you uncheck some of the nodes, the filtering seems to work as expected:
I have attached my sample project. Could you please specify the exact steps how to reproduce the problem? Thank you in advance for your cooperation.
I am looking forward to your reply.
Regards,
Dess | Tech Support Engineer, Sr.
Progress Telerik
Our thoughts here at Progress are with those affected by the outbreak.