Search code examples
wpf

c# wpf Filling datagrid with async await method


Filling datagrid with async await method

I would like to use the function in the above link.

using MySqlConnection con = new(Common.JOIN);
                    con.Open();
                    MySqlCommand cmd = new(
                        $"SELECT * FROM item WHERE CONCAT (`i_type`) like '{type.Text}' ORDER BY `i_name` ASC;", con);
                    MySqlDataAdapter adp = new(cmd);
                    DataSet ds = new();
                    adp.Fill(ds, "LoadDataBinding");
                    datagrid.DataContext = ds;

The tone may be a little odd. I ask a question through Google Translate.

The code I am using is as above.

To use the code I use from the link in the link How do I fix it?

I'm using C# WPF.


Solution

  • If you would replace this line

    datagrid.DataContext = ds;
    

    With this one

    datagrid.ItemsSource = ds.Tables["LoadDataBinding"].DefaultView;
    

    Then it should work