简体   繁体   English

WPF:具有空白单元格的DataGrid

[英]WPF: DataGrid with blanck cells

I am trying to make an app that enables users to enter information into a DataGrid , I am doing this in the code behind. 我正在尝试制作一个使用户能够将信息输入到DataGrid的应用程序,我正在后面的代码中执行此操作。 This is a portion of the code I am using: 这是我正在使用的代码的一部分:

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);
}    

collection has already been declared, also the TabItems are properly inserted into a TabControl . 已经声明了collection,并且TabItems也已正确插入TabControl

For some reason this does not result in giving me what I want (a blank chart). 由于某种原因,这并不能使我得到我想要的东西(空白图表)。 it gives me the column I created plus another column with a Header named Length. 它为我提供了我创建的列以及带有标题为Length的标题的另一列。 Can anyone tell me what I am doing wrong? 谁能告诉我我在做什么错?

您需要将DataGrid.AutoGenerateColumns属性设置为false

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM