TorrBallen
TorrBallen

Reputation: 99

RowFilter only works with column name in C#

my RowFilter in windows form application works just fine with column name which NOT is an integer. But the other fields with integer nothing happens. This is my code:

DV.RowFilter = string.Format("group_id LIKE '%{0}%' ", textBox1.Text); 

If it has to do with the format, have no idea.

Upvotes: 1

Views: 1227

Answers (1)

Tim Schmelter
Tim Schmelter

Reputation: 460058

I wouldn't use RowFilter anymore, since .NET 3.5 you can use Linq-To-DataTable:

var filteredRows = DV.Table.AsEnumerable()
    .Where(row => row.Field<int>("group_id").ToString().Contains(textBox1.Text));

If you need a DataTable:

DataTable filteredTable = filteredRows.CopyToDataTable();

If you need the DataView and overwrite the old:

DV = filteredTable.DefaultView;

I assume that you don't even need the DataView anymore.

Upvotes: 1

Related Questions