2011-04-29 104 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