locked
Setting Datasource to Datagrid In WPF RRS feed

  • Question

  • I Want to know how to set the data returned from database to datagrid IN WPF

    i  c# We could simply set gridview1.datasource=dataset.table[0];

    but in WPF datagrid dont have datasource property.

    Thanks

    Saturday, February 8, 2014 4:01 PM

Answers

  • In WPF you can try following code

    DataGrid1.ItemsSource = dataset.Tables[0].AsDataView();


    Gaurav Khanna | Microsoft VB.NET MVP | Microsoft Community Contributor

    • Proposed as answer by Magnus (MM8)MVP Sunday, February 9, 2014 10:38 AM
    • Marked as answer by Xyzsamm Monday, February 10, 2014 5:03 PM
    Saturday, February 8, 2014 6:44 PM
  • WPF controls that display a collection of data such as a dataset.table use the property ItemsSource to indicate the datasource.


    Lloyd Sheen

    • Proposed as answer by Magnus (MM8)MVP Sunday, February 9, 2014 10:38 AM
    • Marked as answer by Xyzsamm Monday, February 10, 2014 5:04 PM
    Saturday, February 8, 2014 5:30 PM

All replies

  • WPF controls that display a collection of data such as a dataset.table use the property ItemsSource to indicate the datasource.


    Lloyd Sheen

    • Proposed as answer by Magnus (MM8)MVP Sunday, February 9, 2014 10:38 AM
    • Marked as answer by Xyzsamm Monday, February 10, 2014 5:04 PM
    Saturday, February 8, 2014 5:30 PM
  • In WPF you can try following code

    DataGrid1.ItemsSource = dataset.Tables[0].AsDataView();


    Gaurav Khanna | Microsoft VB.NET MVP | Microsoft Community Contributor

    • Proposed as answer by Magnus (MM8)MVP Sunday, February 9, 2014 10:38 AM
    • Marked as answer by Xyzsamm Monday, February 10, 2014 5:03 PM
    Saturday, February 8, 2014 6:44 PM