添加列时出现DataGridView问题

时间:2011-04-29 17:21:49

标签: windows forms datagridview

嘿伙计们!我第一次使用带有C ++的Visual Studio 2008 Windows窗体应用程序。

我想在我的表单上放一个dataGridView。那没问题。但是当添加一列时,gridView上会出现2列。首先没有标题(我不想要),第二个没问题(我的专栏)。我试图从代码中设置列号,但同样的事情发生了。

有什么想法解决这个问题吗?

谢谢,  安德鲁

// 
        // table
        // 
        this->table->AllowUserToAddRows = false;
        this->table->AllowUserToDeleteRows = false;
        this->table->ColumnHeadersHeightSizeMode = System::Windows::Forms::DataGridViewColumnHeadersHeightSizeMode::AutoSize;
        this->table->Columns->AddRange(gcnew cli::array< System::Windows::Forms::DataGridViewColumn^  >(1) {this->Column1});
        this->table->Location = System::Drawing::Point(13, 89);
        this->table->Name = L"table";
        this->table->ReadOnly = true;
        this->table->Size = System::Drawing::Size(240, 150);
        this->table->TabIndex = 2;
        // 
        // Column1
        // 
        this->Column1->HeaderText = L"Column1";
        this->Column1->Name = L"Column1";
        this->Column1->ReadOnly = true;

1 个答案:

答案 0 :(得分:0)

您是在构造函数中添加列吗?

我在过去遇到过一个问题,即构造函数中添加的项目会被添加两次,因为(我认为)构造函数被调用以使控件出现在设计器视图中(然后将其添加到实例中)然后再运行你的程序。

如果您正在发生这种情况,则需要检查您是否处于设计模式。

根据具体情况,有几种不同的方法可以检查这一点 - 请参阅How to tell if .NET code is being run by Visual Studio designer