Exemplo n.º 1
0
        /// <summary>
        /// This method will create a combo drop down, with the specified ComboItems, in the specified cell.
        /// </summary>
        public void CreateComboInCell(DataGridViewCell Cell, string[] ComboItems)
        {
            MyDataGridViewComboBoxCell Combo = new MyDataGridViewComboBoxCell();

            Combo.Items.AddRange(ComboItems);
            ReplaceCell(Cell, Combo);
        }
Exemplo n.º 2
0
 /// <summary>
 /// The edit control (e.g. combo box) is about to be shown. If we added a temporary item
 /// to the combo control (so that the grid doesn't reject a value) then remove it now so
 /// that the user doesn't see it. It will be added in later (OnCellValidating) when the
 /// user has finished editing.
 /// </summary>
 private void OnEditingControlShowing(object Sender, DataGridViewEditingControlShowingEventArgs e)
 {
     ContextMenuStrip = null;
     if (CurrentCell is MyDataGridViewComboBoxCell && EditingControl is DataGridViewComboBoxEditingControl)
     {
         DataGridViewComboBoxEditingControl Combo = (DataGridViewComboBoxEditingControl)EditingControl;
         Combo.DropDownStyle    = ComboBoxStyle.DropDown;
         Combo.AutoCompleteMode = AutoCompleteMode.None;
         Combo.KeyDown         -= new KeyEventHandler(OnComboKeyDown);
         Combo.KeyDown         += new KeyEventHandler(OnComboKeyDown);
         Combo.Leave           -= new EventHandler(OnComboLeave);
         Combo.Leave           += new EventHandler(OnComboLeave);
         MyDataGridViewComboBoxCell MyCombo = (MyDataGridViewComboBoxCell)CurrentCell;
         if (MyCombo.ValueInserted)
         {
             string SavedText = Combo.Text;
             Combo.Items.RemoveAt(0);
             Combo.Text = SavedText;
         }
     }
 }