Рубрика: Заметки

  • Редактирование столбца с типом ComboBox в DataGridView

    private void dataGridView1_EditingControlShowing(object sender, DataGridViewEditingControlShowingEventArgs e) { ComboBox c = e.Control as ComboBox; if (c != null) c.DropDownStyle = ComboBoxStyle.DropDown; } private void dataGridView1_CellValidating(object sender, DataGridViewCellValidatingEventArgs e) { DataGridView dgvForm = (DataGridView)sender; DataGridViewComboBoxCell cell = dgvForm.CurrentCell as DataGridViewComboBoxCell; if (cell != null && !cell.Items.Contains(e.FormattedValue)) { cell.Items.Insert(0, e.FormattedValue); if (dgvForm.IsCurrentCellDirty) { dgvForm.CommitEdit(DataGridViewDataErrorContexts.Commit); } cell.Value = cell.Items[0];…