Click here to Skip to main content
14,740,854 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:

I need search two words in datagrid
If is team AC MILAN
If put word MILAN in text box have multiple values, becose I have basketbal team and footbal team

Need some solution LIKE: %AC%MILAN% (Result find all word in datagrid with AC and MILAN)

What I have tried:

private void SearchListTextBox_TextChanged(object sender, EventArgs e)
            (ListDataGridView.DataSource as DataTable).DefaultView.RowFilter = string.Format("[Team] LIKE '%{0}%' OR [Player] LIKE '%{0}%'", SearchListTextBox.Text);
            countRowsLabel.Text = "Ukupno računa: " + ListDataGridView.RowCount.ToString();
Updated 31-May-20 9:39am

1 solution

Use the string .Split() function to split on the space character:
string[] strings = SearchListTextBox.Text.Split(' ', StringSplitOptions.RemoveEmptyEntries);
Also see:[^]

then search like this:
[Team] LIKE '%{0}%' OR [Team] LIKE '%{1}%', strings[0], strings[1]
Goran Bibic 31-May-20 14:46pm
Where to put .Split() ?
Goran Bibic 31-May-20 14:54pm
(TeamsDataGridView.DataSource as DataTable).DefaultView.RowFilter = string.Format("[Name] LIKE '%{0}%' OR [SubName] LIKE '%{1}%' OR [Sport] LIKE '%{2}%'", SearchListTextBox.Text);

Where to put .Split() ?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900