private void indexGrid_EditingControlShowing(object sender, DataGridViewEditingControlShowingEventArgs e)
{
Type t = e.Control.GetType();
if (t != typeof(DataGridViewComboBoxEditingControl)) return;
DataGridViewComboBoxEditingControl ec = e.Control as DataGridViewComboBoxEditingControl;
ec.DrawMode = DrawMode.OwnerDrawFixed;
ec.DrawItem += new DrawItemEventHandler(dropdown_DrawItem);
if (indexGrid.CurrentCell.ColumnIndex == 0)
{
// now we need to set the item list to all non used columns and the option of
// NONE
ec.Items.Clear();
ec.Items.Add("<None>");
foreach (string s in columnNames)
{
bool alreadyUsed = false;
if (s != (string)indexGrid.CurrentRow.Cells[0].Value)
foreach (IndexColumnGridRow row in gridRows)
if (row.ColumnName == s)
{
alreadyUsed = true;
break;
}
if (!alreadyUsed)
ec.Items.Add(s);
}
int index = ec.FindStringExact(indexGrid.CurrentRow.Cells[0].Value as string);
if (index > 0)
ec.SelectedIndex = index;
}
}