How to bind a datagrid with datatable in wpf ? RRS feed

  • Question

  • Hi all,

    Here is my code , but its not working .

    DataTable aTable = new DataTable();
                aTable.Columns.Add(new DataColumn("ProductID", typeof(int)));
                aTable.Columns.Add(new DataColumn("ProductName", typeof(string)));

                aTable.Rows.Add(12, "Lap top");
                aTable.Rows.Add(13, "bbb");
                aTable.Rows.Add(14, "ccc");

                this.DataContext = aTable;


    MSDN Forum

    • Moved by Lisa Zhu Wednesday, May 23, 2012 3:12 AM Issue about WPF (From:Visual C# General)
    Monday, May 21, 2012 5:55 AM


  • Hi Amal E S,

    DataGrid.ItemsSource = DataTableName.DefaultView();

    Best regards,

    Sheldon _Xiao[MSFT]
    MSDN Community Support | Feedback to us
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Wednesday, May 23, 2012 5:28 AM

All replies