Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

RowFilter/DataGrid Question

Status
Not open for further replies.

Slonoma

Programmer
Jul 10, 2003
41
US
Hi all,
I am displaying a report using a DataGrid. I am using a RowFilter to get only the records I need to display.

One of the fields, contains 3 different string values. I need to display that record based on if ANY of those values are equal to what the user selected from a dropdown.

Ex.
user selected "This item" from dropdown.

if the field returned is "That item, This item, Another item"..... is there a way to check to see if "This item" is in the field? (In this case it is)

Thanks! Slo-no

The trouble with programmers is that they get high on their own supply. -Dimandja
 
Code:
string strFilter = "MyItemsColumn LIKE '*" + userSelection.ToString().Trim() + "*'";
DataView dv = new DataView();
dv.Table = DataSet1.Tables["Suppliers"];
dv.RowFilter = strFilter;
where MyItemsColumn is the column with 3 values and userSelection is the string that user selected
In your case the filter will be : "MyItemsColumn LIKE '*This Item*'"
Note that the wildcards are not allowed inside of the text to search.
obislavu
 
Thanks obislavu,
It works great. I did have to some tweaking.

the field contains items like "Nike Brands" as well as "Nike Brands Contact" and can combine them like "Nike Brands Contact, Nike Brands".

So if I looked for "Nike Brands", it would return everything with "Nike Brands" as well as "Nike Brands Contact".

Heres the fix: (alname LIKE '" + searchFilter +"' AND alname NOT LIKE '" + searchFilter " ')

Notice the space after the second searchFilter. This would eliminate "Nike Brands Contact" but keep "Nike Brands" (as they are separated by commas and not spaces)

Cheers,
Slo-no

The trouble with programmers is that they get high on their own supply. -Dimandja
 
Okay, you know how the info is structured and you can arrange the string filter accordingly.
obislavu
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top