0
private void dataGridViewSales_EditingControlShowing(object sender, DataGridViewEditingControlShowingEventArgs e)
{
  if (this.dataGridViewSales.CurrentCell.ColumnIndex == 1)
  {
    ComboBox c = e.Control as ComboBox;
    ((ComboBox)c).AutoCompleteSource = AutoCompleteSource.ListItems;
    ((ComboBox)c).AutoCompleteMode = AutoCompleteMode.SuggestAppend;
    ((ComboBox)c).DropDownStyle = ComboBoxStyle.DropDown;
  }
}

使用上面的代码,我遇到了一个问题,在从自动完成组合框中进行选择后,当我通过按 Tab 键退出组合框单元格时,我失去了选择。有时,选择被保留,有时选择被清除,它有点随机发生。

4

1 回答 1

0

处理 CurrentCellDirtyStateChanged 事件解决了这个问题,但我希望它不会导致其他问题!

private void dataGridView1_CurrentCellDirtyStateChanged(object sender, EventArgs e)
        {
            if (dataGridView1.IsCurrentCellDirty)
            {
                dataGridView1.CommitEdit(DataGridViewDataErrorContexts.Commit);
            }
        }
于 2012-07-18T06:04:58.407 回答