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

SFdatagrid Filter Search field accepting Special character.

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

1 Reply

MA Mohanram Anbukkarasu Syncfusion Team 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  

Live Chat Icon For mobile
Up arrow icon