.NET BindingSource.Filter with Regular Expressions

I use BindingSource.Filter to list only specific elements of a data source. I especially use it so much:

m_bindingSourceTAnimation.Filter = "Name LIKE '" + FilterText + "'";

now my question is: if you can somehow use regular expressions with these filters.

I especially need some wildcard characters (*), like

*hello*world*

thanks!

+5
source share
5 answers

You can easily query a DataTable using LINQ, and then you can use the actual Regex in the query to filter it anyway.

Something like that...

var source = myDataTable.AsEnumerable();

var results = from matchingItem in source
              where Regex.IsMatch(matchingItem.Field<string>("Name"), "<put Regex here>")
              select matchingItem;

//If you need them as a list when you are done (to bind to or something)
var list = results.ToList();

, Regex, , , Regex.

**** ** -

, , , , , DataTable Grid - . , , "" , DataSource ( BindingSource), , . DataTables, , , , , ( , google ).

+10

BindingSource IBindingListView.Filter . . DataTable/DataView? , DataView.RowFilter, , .

DataView , LIKE * - FilterText - "Foo*Bar*". , .


, DataTable/DataView... (bool) . / ( ) , " ". , , , /.


( DataTable), LINQ. , , (Where(string)), , / RowFilter. , , ?

+5

:

"... (bool) . / ( ) " ". , , , /-."

, , , /dataview, , . , .

+1

, , , split.

Array a = SearchString.Split('*');
string rowFilter = "";

if (a.GetUpperBound(0) == 1)
{

  rowFilter = "(MODEL_NBR like '" + a.GetValue(0).ToString() + "*' AND MODEL_NBR like '*"      + a.GetValue(1).ToString() + "')";

 }

, , expressio

+1
    '[Description] Is column name
    Dim SearchStrArr() As String = Split(txtSearch.Text, " ")
    Dim FilterString As String = "" 
    FilterString = String.Join("%' AND [Description] Like '%", SearchStrArr)
    FilterString = "[Description] Like '%" & FilterString & "%'"

    m_bindingSourceTAnimation.Filter = FilterString 
0

All Articles