不能在数据绑定的DataGridView控件上设置ColumnCount属性

本文关键字:设置 ColumnCount 属性 控件 DataGridView 数据绑定 不能 | 更新日期: 2023-09-27 18:12:11

请帮助我知道我的代码有什么问题,我被这个错误卡住了,所以请帮助我。由于

       InitializeComponent();

        studentInfoDataGridView.ColumnCount = 6;
        studentInfoDataGridView.Columns[0].Name = "ID";
        studentInfoDataGridView.Columns[1].Name = "FirstName";
        studentInfoDataGridView.Columns[2].Name = "LastName";
        studentInfoDataGridView.Columns[3].Name = "Course";
        studentInfoDataGridView.Columns[4].Name = "StudentSection";
        studentInfoDataGridView.Columns[5].Name = "StudentNumber";

        studentInfoDataGridView.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill;
        studentInfoDataGridView.SelectionMode = DataGridViewSelectionMode.FullRowSelect;
        studentInfoDataGridView.MultiSelect = false;

不能在数据绑定的DataGridView控件上设置ColumnCount属性

您不需要设置ColumnCount,只需使用StudentInfoDataFridView.Columns.Add("什么");