2011-04-29 99 views
0

嘿,伙计们!我第一次使用Visual Studio 2008 Windows Form Application与C++。添加列时出现DataGridView问题

我想把一个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; 
+0

你可以发布一个简单的例子吗? – 2011-04-29 17:27:38

+0

我编辑了我的帖子并添加了示例代码 – Andrew 2011-04-29 18:11:58

+0

请问您可以用语言标记问题。它看起来像c + + – 2011-04-29 19:36:59

回答

0

你将在构造函数中列?

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

如果这是你正在发生的事情,你需要检查你是否处于设计模式。

有几种不同的方式来检查这一点,根据上下文 - 见How to tell if .NET code is being run by Visual Studio designer

+0

它发生在运行时和窗体设计器(从2个不同的项目运行)。 – Andrew 2011-04-29 17:54:31