首先是我的问题:我想为DataGrid
动态过滤TextBox
动态Name
。
我目前的代码:
如何填充DataGrid
:
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;
TextBox
的代码:
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);
}
看起来像这样:
答案 0 :(得分:1)
将您的代码更改为:
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;
}