Обновление таблицы winforms
Вот весь код с нахождения пользователя по имени
private void textBox1_TextChanged(object sender, EventArgs e)
{
adapter = new SqlDataAdapter("SELECT * FROM Devices where Name like '%"+txtSearch.Text.ToString()+"%'" , db);
dt = new DataTable();
adapter.Fill(dt);
Grid_Devices.Rows.Clear();
foreach (DataRow dr in dt.Rows)
{
int n = Grid_Devices.Rows.Add();
Grid_Devices.Rows[n].Cells[0].Value = dr[0].ToString();
Grid_Devices.Rows[n].Cells[1].Value = dr[1].ToString();
Grid_Devices.Rows[n].Cells[2].Value = dr[2].ToString();
Grid_Devices.Rows[n].Cells[3].Value = dr[3].ToString();
}
}
Ответы (1 шт):
Автор решения: tomato-magnet-regulato
→ Ссылка
try
{
(dataGrid.DataSource as DataTable).DefaultView.RowFilter = string.Format("nameTable LIKE '%{0}%' OR nameTable LIKE '%{0}%'", textBox.Text);
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
Как ищу я. Не помню где взял.