开发者

DataGridView problem when adding columns

开发者 https://www.devze.com 2023-03-02 04:45 出处:网络
Hey guys! First time I use Visual Studio 2008 Windows Form Application with C++. I want to put a dataGridView on my form. That is ok. But when adding one column, on the gridView appear 2 columns. Fir

Hey guys! First time I use Visual Studio 2008 Windows Form Application with C++.

I want to put a dataGridView on my form. That is ok. But when adding one column, on the gridView appear 2 columns. First with no header (which I dont want) and the second is ok(my column). I tried to set the column number from code, but the same thing happens.

Any idea to solve this?

Thanks, Andrew

// 
        // table
        // 
        this->table->AllowUserToAddRows = false;
        this->table->AllowUserToDeleteRows = false;
        this->table->ColumnHeadersHeightSizeMode = System::Windows::Forms::DataGridViewColumnHeadersHeightSize开发者_如何学PythonMode::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;


Are you adding the column in the constructor?

I've had a problem in the past where items added in the constructor get added twice, because (I think) the constructor gets called to make the control appear in the designer view, (which then gets added to the instance) and then again when you run your program.

If that is what's happening for you, you need to check that you aren't in design mode.

There are a few different ways to check this, depending on context - see How to tell if .NET code is being run by Visual Studio designer

0

精彩评论

暂无评论...
验证码 换一张
取 消