过滤WPF DataGrid C#由MySQL填充

时间:2015-10-09 11:22:57

标签: c# mysql wpf datagrid

我想在用户输入搜索框时过滤我的DataGrid。我通过以下方法将数据绑定到DataGrid;

在我的DataAccessor中;

    public DataTable FillDataGrid()
    {
        string constr = ConfigurationManager.ConnectionStrings["dbfString"].ConnectionString;
        using (OleDbConnection dbfCon = new OleDbConnection(constr))
        {
            try
            {
                dbfCon.Open();
                DataTable dTable = new DataTable();
                string dbfQuery = "SELECT em_pplid, em_name, em_netname, em_init, em_dept FROM employs WHERE em_netname NOT LIKE ''";
                OleDbCommand MyQuery = new OleDbCommand(dbfQuery, dbfCon);
                OleDbDataAdapter DA = new OleDbDataAdapter(MyQuery);
                DA.Fill(dTable);
                return dTable;
            }
            catch (OleDbException)
            {
                throw;
            }
        }
    }

在我看来;

    private void FillDataGrid(object sender, RoutedEventArgs e)
    {
        DataAccessor da = new DataAccessor();
        DataTable dt = da.FillDataGrid();
        dataGrid.ItemsSource = dt.AsDataView();
    }

另外在我看来,当我知道如何正确过滤DataGrid时,我现在已经准备好成为搜索功能;

    private void SearchGrid(object sender, TextChangedEventArgs e)
    {
        if (nNameRad.IsChecked == true)
        {
            MessageBox.Show("Hello!");
        }
    }

我在网上搜索过,发现了一些看似过时的过滤DataGrid的方法。我怎么能在我的程序中这样做?

0 个答案:

没有答案