2014-12-03 59 views
0

我試圖製作一個應用程序,使用戶可以將信息輸入到DataGrid中,我在後面的代碼中執行此操作。這是我使用的代碼的一部分:WPF:帶有blanck單元格的DataGrid

for(int i = 1; i < 9; i++) 
{ 
    collection = new ObservableCollection<string>(); 

    //Create a new tab and a new grid to fill the tab number i 
    TabItem classTab = new TabItem(); 
    DataGrid dataGrid = new DataGrid(); 

    dataGrid.FontFamily = new FontFamily("Times New Roman"); 
    dataGrid.FontSize = 18; 
    dataGrid.CanUserAddRows = true; 


    dataGrid.Columns.Add(new DataGridTextColumn() 
    { 
     Width = 800, 
     Header = "الفوج أ" 
    }); 


    if(i == 8) 
    { 
     classTab.Header = "القسم الثانوي"; 
    } 
    else 
    { 
     if (i == 7) 
     { 
      classTab.Header = "القسم الإعدادي"; 
     } 
     else 
     { 
      classTab.Header = "القسم" + " " + i.ToString(); 
     } 

    } 

    dataGrid.ItemsSource = collection; 
    classTab.Content = dataGrid; 

    //Insert class tab into classes 
    classes.Items.Add(classTab); 
}  

收藏已聲明,也TabItems正確插入TabControl

出於某種原因,這不會導致我想要的東西(空白圖表)。它爲我提供了我創建的列以及帶有名爲Length的標題的另一列。 誰能告訴我我做錯了什麼?

回答