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
1 2 3 4 5 6 7 8 | private void txtSearch_TextChanged(object sender, EventArgs e) { DataView dv = dt.DefaultView; dv.RowFilter = "Name + Country LIKE '%" + txtSearch.Text + "%'"; dgwCustomers.DataSource = dv; } |