- foreach (DataRow dataRow in dt.Rows)
- {
- if (dataRow["Column1"].ToString().Contains(["ExampleString"])
- {
- listBox1.Items.Add(dataRow["Column1"] + " " + dataRow["Column2"] + " " + dataRow["Column3"] + " " + dataRow["Column4"]);
- }
- }
- //the above code works perfectly and returns only the rows containing the "ExampleString"
- // if i try to use a SelectedText value from a combobox as a string to replace the "ExampleString", (as shown below),the listbox populates with ALL of the rows, not just the ones with the "ExampleString".
- string strFromCombobox = comboBox1.SelectedText;
- foreach (DataRow dataRow in dt.Rows)
- {
- if (dataRow["Column1"].ToString().Contains(strFromCombobox)
- {
- listBox1.Items.Add(dataRow["Column1"] + " " + dataRow["Column2"] + " " + dataRow["Column3"] + " " + dataRow["Column4"]);
- }
- }
Loading

Riddhi ValechaRank #794 · 2.9K reputationPosted Apr 27, 2016, 10:11 PM EDT
Purba Anggara112 reputationPosted Apr 27, 2016, 4:21 PM EDT
Purba Anggara112 reputationPosted Apr 27, 2016, 4:24 PM EDT
ali tuncerRank #1,498 · 1.1K reputationPosted Apr 27, 2016, 5:17 PM EDT
David6 reputationPosted Apr 28, 2016, 3:25 AM EDT