Вопрос

I am currently working on a form and I would like to filter entries based on different columns. The column on which the filtering will take place can be selected by the user by using a combobox. Under it I have placed a text box which will have the term which is being searched for. The problem is that I don't know how to modify the column argument depending on the choice made by the user. If anyone could help me out with that, it would be awesome. Here is the text box code (i.e. textbox = search box):

private void searchBox_TextChanged (object sender, EventArgs e)
    {
    string selected_field = comboSort.Items[this.comboSort.SelectedIndex].ToString();
    DataView dataView = new DataView (dataset);
    dataView.RowFilter = string.Format("selected_field LIKE '%{0}%'",searchBox.Text);
    dataGridView1.DataSource = dataView;
    }
Это было полезно?

Решение

Use string format just as you did with search text:

dataView.RowFilter = String.Format("{0} LIKE '%{1}%'", selected_field, searchBox.Text);
Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top