首先是我的问题:我想用DataGrid
动态过滤我的TextBox
。
我的当前代码:
如何填写Name
:
cnb1 = new MySqlConnectionStringBuilder();
cnb1.Server = "xxxxxxxxxxxxxxxxxxx";
cnb1.Database = "xxxxxxxxxxxxxxx";
cnb1.UserID = "xxxxxxxxxxxxxxxxx";
cnb1.Password = "xxxxxxxxxxxxxxxxxx";
cn1 = new MySqlConnection(cnb1.ConnectionString);
cn1.Open();
da = new MySqlDataAdapter("SELECT * FROM AktuelleDaten", cn1);
da.MissingSchemaAction = MissingSchemaAction.AddWithKey;
da.SelectCommand.ExecuteNonQuery();
ds = new DataSet();
da.Fill(ds);
hauptübersichtgrid.ItemsSource = ds.Tables[0].DefaultView;
DataGrid
的代码:private void TextBox_TextChanged(object sender, TextChangedEventArgs e)
{
DataSet DV = ds;
hauptübersichtgrid.ItemsSource = DV.Tables[0].DefaultView.RowFilter = string.Format("Name like '%{0}%'", Filter.Text);
}
看起来是这样的:
最佳答案
将代码更改为:
private void TextBox_TextChanged(object sender, EventArgs e)
{
DataView dv = ds.Tables[0].DefaultView;
dv.RowFilter = string.Format("Name like '%{0}%'", Filter.Text);
hauptübersichtgrid.ItemsSource = dv;
}