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
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

SFdatagrid Filter Search field accepting Special character.

Thread ID:





149347 Nov 22,2019 11:23 AM UTC Nov 25,2019 01:00 PM UTC WPF 1
Tags: SfDataGrid
Asked On November 22, 2019 11:27 AM UTC

Hi team,
    I am using the Filter feature of Datagrid in my WPF project. I need to restrict special characters in the filter search field. Can you please help us with this issue?

Thank you,

Attachment: Syncfusion_Filter_ac277d19.7z

Mohanram Anbukkarasu [Syncfusion]
Replied On November 25, 2019 01:00 PM UTC

Hi Brijesh   
Thanks for contacting Syncfusion support.    
Your requirement to restrict special characters in the search text box on the filter control by handling the PreviewTextInput of the search text box using theSfDataGrid.FilterItemsPopulating event can be achieved as shown in the below code example.    
Code example:   
this.dataGrid.FilterItemsPopulating += DataGrid_FilterItemsPopulating;   
private void OnDataGrid_FilterItemsPopulating(object sender, GridFilterItemsPopulatingEventArgs e)   
    var filterControl = e.FilterControl;   
    CheckboxFilterControl checkBoxFilterControl = (CheckboxFilterControl)filterControl.GetType().GetField("CheckboxFilterControl", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance).GetValue(filterControl);   
    checkBoxFilterControl.Loaded += OnCheckBoxFilterControl_Loaded;   
void OnCheckBoxFilterControl_Loaded(object sender, RoutedEventArgs e)   
    CheckboxFilterControl checkBoxFilterControl = sender as CheckboxFilterControl;   
    TextBox searchTextBox = (TextBox)checkBoxFilterControl.GetType().GetField("SearchTextBox", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance).GetValue(checkBoxFilterControl);   
    if (searchTextBox != null)   
        searchTextBox.PreviewTextInput += OnSearchTextBox_PreviewTextInput;   
private void OnSearchTextBox_PreviewTextInput(object sender, TextCompositionEventArgs e)   
    e.Handled = !IsTextAllowed(e.Text, @"[^a-zA-Z]");   
private static bool IsTextAllowed(string Text, string AllowedRegex)   
        var regex = new Regex(AllowedRegex);   
        return !regex.IsMatch(Text);   
        return true;   
We have prepared a sample using the above code example and it is available in the below link for your reference.   
Please let us know if you require further other assistance from us.    
Mohanram A  


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.

Please sign in to access our forum

This page will automatically be redirected to the sign-in page in 10 seconds.

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

Live Chat Icon For mobile
Live Chat Icon