I am using WPF Data-grid with auto-generated columns. I am assigning data-table with one column but no rows as Items-source.
public DataTable GetInitData()
{
empDS = new DataSet();
empTbl = new DataTable();
empDS.Tables.Add(empTbl);
dc = new DataColumn("Test");
empDS.Tables[0].Columns.Add(dc);
empDS.AcceptChanges();
return empDS.Tables[0];
}
and I call the method above in the constructor.
public MainWindow()
{
this.InitializeComponent();
this.grdEmp.ItemsSource = this.GetInitData().DefaultView;
}
Screen-shot:

Now when I press F5 and run the code… the Data-grid doesn’t show any column. Please guide me, why it is not showing any column. If you need any other information do let me know.
Regards,
Priyank
If you add a single row to your table you will see the column generated. Therefore, I can only suggest this is a limitation (bug?) in the WPF
DataGrid. Depending on what you’re trying to achieve, you might like to add an empty row to your data first.