I’ve written the following code to display some data, but the data grid is just appearing empty,
here is my code:
DataTable dt = new DataTable();
DataColumn col = new DataColumn("A", typeof(string));
col.MaxLength = 100;
dt.Columns.Add(col);
col = new DataColumn("B", typeof(string));
col.MaxLength = 100;
dt.Columns.Add(col);
DataRow row = dt.NewRow();
dt.Rows.Add(x,y);
dataGrid1.ItemsSource = dt.DefaultView;
Do you have
AutoGenerateColumns="True"in your DataGrid declaration? e.g.For more precise control over column definitions, add a
DataGrid.Columnselement: