Hi,
On a form, there is a datagridview that I fill with the help of a query that reads a SQlite table.
After the datagridview shows the data I want to provide 1 column with a combobox and in the list of the combobox all values from that column must be included.
What I have so far does not work properly. I can click twice on a cell and choose a value from the combobox list. Sometimes it works and sometimes I get:
"Message" Operation is not valid because it results in a reentrant call to the SetCurrentCellAddressCore function. "
It seems like it only works in the first 2 rows.
What is wrong?
private DataGridViewComboBoxCell comboCell;
private List<string> exportLocation = new();
private void DataGridViewQgroups_CellEnter(object sender, DataGridViewCellEventArgs e)
{
this.exportLocation.Clear();
this.comboCell = new();
this.comboCell = this.CreateComboBoxItemlist(this.DataGridViewQgroups);
if (e.ColumnIndex == 3 && this.comboCell.DataSource != null)
{
this.DataGridViewQgroups.Rows[e.RowIndex].Cells[3] = (DataGridViewComboBoxCell)this.comboCell;
this.DataGridViewQgroups.BeginEdit(true);
((ComboBox)this.DataGridViewQgroups.EditingControl).DroppedDown = true;
}
}
private DataGridViewComboBoxCell CreateComboBoxItemlist(DataGridView dgv)
{
// Create the list only once
if (this.exportLocation.Count == 0)
{
string columnName = "Export_locatie";
foreach (DataGridViewRow item in this.DataGridViewQgroups.Rows)
{
if (item.Cells[columnName].Value != null)
{
this.exportLocation.Add(item.Cells[columnName].Value.ToString());
}
}
DataGridViewComboBoxCell combo = new DataGridViewComboBoxCell();
combo.DataSource = this.exportLocation;
combo.AutoComplete = true;
combo.MaxDropDownItems = 10;
combo.FlatStyle = FlatStyle.Flat;
combo.DisplayStyle = DataGridViewComboBoxDisplayStyle.Nothing; // You see only a combobox when editing
return combo;
}
else
{
return null;
}
}


