Hey all, i'm currently building a datagridview out of a SQL database.
Since i need 4 columns to display a combocellbox instead of a normal textcell, i create said comboboxcells and genereate new columns for the gridview.
When i run the program the first time, everything is completly fine, all data and comboboxes are fine.
If i then push the "refresh" button, which calls the same function which is run at startup of the program, i get a index out of range error when i want to add the new columns with the combobox.
I searched for hours now and just can't find the cause of this, all variables seem to have the same value on startup and on refresh.
The code breaks at this point at the second line when inserting:
DataGridViewColumn seccolumn = new DataGridViewColumn(secbox);
dataGridView1.Columns.Insert(18,seccolumn);
dataGridView1.Columns[18].HeaderText = dataGridView1.Columns[9].HeaderText;
dataGridView1.Columns[9].Visible = false;Before trying to insert with index specified, i had the code this way:
DataGridViewColumn seccolumn = new DataGridViewColumn(secbox);
dataGridView1.Columns.Add(seccolumn);
dataGridView1.Columns[18].HeaderText = dataGridView1.Columns[9].HeaderText;
dataGridView1.Columns[9].Visible = false;The used variable "secbox" is the filled combocellbox, in both cases it holds the same data (at first rund and when refreshing)
the function also clears the gridview as followed before building it again:
dataGridView1.DataSource = null; dataGridView1.ClearSelection(); dataGridView1.Columns.Clear(); dataGridView1.Rows.Clear(); dataGridView1.DataBindings.Clear(); dataGridView1.Refresh();
Any tips would be helpfull !
Thanks in advance !