private void textBox2_TextChanged(object sender, EventArgs e) { if (checkBox1.Checked && !textBox2.Text.Contains(" ") && !textBox2.Text.Contains("-") && (!FileBLL.IsEnCh(textBox2.Text) && !FileBLL.IsNum(textBox2.Text))) { string[] id = FileBLL.GetId(textBox2.Text); textBox2.Text = id[0] + " " + id[1]; } if (textBox2.Text.Contains("`")) { textBox2.Text = ""; DBHelper.connstr = this.textBox3.Text; refresh(); } string[] searchStr = textBox2.Text.ToLower().Split(' '); bool flag = true; List <MyFileInfo> newList = new List <MyFileInfo>(); for (int i = 0; i < list.Count; i++) { flag = true; for (int j = 0; j < searchStr.Length; j++) { if (!(list[i].Directory.ToLower().Contains(searchStr[j]) || list[i].FileName.Substring(0, list[i].FileName.LastIndexOf('.') >= 0 ? list[i].FileName.LastIndexOf('.') : list[i].FileName.Length).ToLower().Contains(searchStr[j]) || list[i].Mark.ToLower().Contains(searchStr[j]))) { flag = false; break; } } if (flag) { newList.Add(list[i]); } } this.dataGridView1.DataSource = newList; //list = newList; dataGridView1.Refresh(); }