I get a problem when adding columns to a dataGrid.
I keep adding columns with the code below.
It works well until the column will come outside the right side of the dataGrids Widh.
When it does, the program will get stuck for 2 minutes or so and the column was added.
I have both scrollbars on the dataGrid.

Anyone who can think of why this happen or have got the same problem before.

dataGridView1->Columns->Add(); //Add 1 more Column

I have found out the exact difference of my problem. If I add columns to the dataGridView like this using a button, it will work.

for( int i = 0 ; i < 20; i++)
{
	 dataGridView1->Columns->Add("a", "b"); //Add 20 columns
}

But if I will let the backgroundworker do it like this, the whole application gets stuck completely and I must close the program with taskmanger.
I cant figure it out what the difference are. It is exactly the same code initially that is running ?
Could wonder if it is a bug.

backgroundWorker1->RunWorkerAsync(); //Start backgroundworker
private: System::Void backgroundWorker1_DoWork(System::Object^  sender, System::ComponentModel::DoWorkEventArgs^  e) 
{
      for( int i = 0 ; i < 20; i++)
     {
     	 dataGridView1->Columns->Add("a", "b"); //Add 20 columns
     }
}
backgroundWorker1->CancelAsync();
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.