>public class MyComboBox : ComboBox > { > public MyComboBox() : base() > { > this.KeyUp += new KeyEventHandler(TestKey); > } > > protected override bool IsInputKey(Keys keyData) > { > if (keyData==Keys.Tab) > { > return true; > } > return base.IsInputKey(keyData); > } > > public void TestKey(object sender, KeyEventArgs e) > { > if (e.KeyCode == Keys.Tab) > { > Form f = new Form(); > f.Text = "Modeless lookup form"; > f.Show(); > } > } > } >>
>>>>using System; >>>>using System.Windows.Forms; >>>> >>>>class ComboBoxColumn : DataGridViewComboBoxColumn { >>>>} >>>> >>>>class ComboBoxCell : DataGridViewComboBoxCell { >>>> >>>>public override Type EditType { >>>> >>>>get { >>>>return typeof(ComboBoxEditingControl); >>>>} >>>>} >>>> >>>>} >>>> >>>>class ComboBoxEditingControl : MyComboBox, IDataGridViewEditingControl { >>>> >>>>protected int rowIndex; >>>>protected DataGridView dataGridView; >>>>protected bool valueChanged = false; >>>> >>>>protected override void OnTextChanged(EventArgs e) { >>>> >>>>base.OnTextChanged(e); >>>>NotifyDataGridViewOfValueChange(); >>>>} >>>> >>>>protected virtual void NotifyDataGridViewOfValueChange() { >>>>this.valueChanged = true; >>>> >>>>if (this.dataGridView != null) { >>>>this.dataGridView.NotifyCurrentCellDirty(true); >>>>} >>>> >>>>} >>>> >>>>public Cursor EditingPanelCursor { >>>> >>>>get { >>>>return Cursors.IBeam; >>>>} >>>> >>>>} >>>> >>>>public DataGridView EditingControlDataGridView { >>>>get { >>>>return this.dataGridView; >>>>} >>>> >>>>set { >>>>this.dataGridView = value; >>>>} >>>>} >>>> >>>>public object EditingControlFormattedValue { >>>> >>>>set { >>>> >>>>if (value.ToString() != this.Text) { >>>> >>>>this.Text = value.ToString(); >>>> >>>>NotifyDataGridViewOfValueChange(); >>>> >>>>} >>>> >>>>} >>>> >>>>get { >>>> >>>>return this.Text; >>>> >>>>} >>>> >>>>} >>>> >>>>public object GetEditingControlFormattedValue(DataGridViewDataErrorContexts >>>>context) { >>>> >>>>return this.Text; >>>> >>>>} >>>> >>>> >>>> >>>>public void PrepareEditingControlForEdit(bool selectAll) { >>>> >>>>} >>>> >>>>public bool RepositionEditingControlOnValueChange { >>>> >>>>get { >>>>return false; >>>>} >>>>} >>>> >>>>public int EditingControlRowIndex { >>>> >>>>get { >>>>return rowIndex; >>>>} >>>> >>>>set { >>>>this.rowIndex = value; >>>>} >>>>} >>>> >>>>public void ApplyCellStyleToEditingControl(DataGridViewCellStyle >>>>dataGridViewCellStyle) { >>>>DropDownStyle = ComboBoxStyle.DropDown; >>>>} >>>> >>>>public bool EditingControlWantsInputKey(Keys keyData, bool >>>>dataGridViewWantsInputKey) { >>>>return !dataGridViewWantsInputKey; >>>>} >>>> >>>>public bool EditingControlValueChanged { >>>> >>>>get { >>>>return valueChanged; >>>>} >>>> >>>>set { >>>>valueChanged = value; >>>>} >>>>} >>>> >>>> >>>> >>>>public class Form1 : Form { >>>> >>>>private DataGridView dataGridView1 = new myDataGridView(); >>>> >>>>[STAThread] >>>>public static void Main() { >>>>try { >>>>Application.Run(new Form1()); >>>>} >>>>catch (Exception e) { >>>>MessageBox.Show(e.ToString()); >>>>} >>>>} >>>> >>>>public Form1() { >>>>this.Controls.Add(this.dataGridView1); >>>>this.Load += new EventHandler(Form1_Load); >>>>} >>>> >>>>private void Form1_Load(object sender, EventArgs e) { >>>> >>>>ComboBoxColumn comboBoxColumn = new ComboBoxColumn(); >>>>ComboBoxCell ComboBoxCell = new ComboBoxCell(); >>>>comboBoxColumn.CellTemplate = ComboBoxCell; >>>>dataGridView1.Columns.Add(comboBoxColumn); >>>>} >>>>} >>>>} >>>> >>>>public class MyComboBox : ComboBox { >>>> >>>>protected override void OnValidating(System.ComponentModel.CancelEventArgs >>>>e) { >>>> >>>>e.Cancel = true; >>>>base.OnValidating(e); >>>>Form f = new Form(); >>>>f.Text = "Modeless lookup form"; >>>>f.Show(); >>>>} >>>>} >>>> >>>>public class myDataGridView : DataGridView { >>>> >>>>protected override void OnDataError(bool displayErrorDialogIfNoHandler, >>>>DataGridViewDataErrorEventArgs e) { >>>>e.Cancel = false; >>>>} >>>>} >>>>