Filtering DataView With Multiple Columns in C# – Programming, Pseudocode Example, C# Programming Example
C# Windows Form

Filtering DataView With Multiple Columns in C#

In C#, you can use the DataView.RowFilter property to filter a DataView based on multiple columns. The RowFilter property is a string that represents the filter criteria for the DataView.

The code you provided is an example of how to filter a DataView based on the value of a textbox, in this case, the textbox is named “txtSearch”. The DataView is being created based on a DataTable named “dt” and the filtered data is being displayed in a DataGridView named “dgwCustomers”.

The RowFilter property of the DataView is being set to a string that includes the value of the textbox. The string uses the LIKE operator to match any rows where the combined values of the “Name” and “Country” columns contain the value of the textbox. The % characters are wildcards that match any number of characters before or after the value of the textbox.

The filtered DataView is then being set as the DataSource of the DataGridView, which will display the filtered data.

This code will work as it is however, it will be more secure and efficient to use parameterized query instead of string concatenation.

C# Code

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.