首先是我的问题:我想用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);
}

看起来是这样的:
c# - 使用TextBox动态过滤DataGrid的名称-LMLPHP

最佳答案

将代码更改为:

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;
}

10-06 13:21