protected override void OnEditingControlShowing(DataGridViewEditingControlShowingEventArgs e) { base.OnEditingControlShowing(e); Debug.WriteLine("OnEditingControlShowing"); do { if (m_customCtrl != null) { break; } m_autoCompleteData = m_tblInfo.m_cols[CurrentCell.ColumnIndex].m_lookupData; if (m_autoCompleteData == null) { break; } AutoCompleteStringCollection col = m_autoCompleteData.m_colls; DataGridViewTextBoxEditingControl edt = (DataGridViewTextBoxEditingControl)e.Control; edt.AutoCompleteMode = AutoCompleteMode.SuggestAppend; edt.AutoCompleteSource = AutoCompleteSource.CustomSource; edt.AutoCompleteCustomSource = col; edt.Validated += Edt_Validated; } while (false); }
//data table has single column public myComboBox(DataGridView dgv, lDataSync data) : base(dgv) { m_combo = new ComboBox(); m_combo.DataSource = data.m_bindingSrc; DataTable tbl = (DataTable)data.m_bindingSrc.DataSource; m_combo.DisplayMember = tbl.Columns[1].ColumnName; m_combo.SelectedValueChanged += ctrl_ValueChanged; }
private void Edt_Validated(object sender, EventArgs e) { TextBox edt = (TextBox)sender; Debug.WriteLine("Edt_Validated:" + edt.Text); string selectedValue = edt.Text; if (selectedValue != "") { m_autoCompleteData.Update(selectedValue); } m_autoCompleteData = null; edt.Validated -= Edt_Validated; }
protected override void OnCellEndEdit(DataGridViewCellEventArgs e) { base.OnCellEndEdit(e); Debug.WriteLine("OnCellEndEdit"); HideCustomCtrl(); //update selected value lDataSync data = m_tblInfo.m_cols[e.ColumnIndex].m_lookupData; if (data != null && CurrentCell.Value != null) { string key = CurrentCell.Value.ToString(); string val = data.find(key); if (val != null) { CurrentCell.Value = val; } } }
protected override void OnEditingControlShowing(DataGridViewEditingControlShowingEventArgs e) { base.OnEditingControlShowing(e); Debug.WriteLine("OnEditingControlShowing"); var col = m_tblInfo.m_cols[CurrentCell.ColumnIndex]; switch (col.m_type) { case TableInfo.ColInfo.ColType.map: ToolTip tt = new ToolTip { IsBalloon = true, InitialDelay = 0, ShowAlways = true }; tt.SetToolTip(e.Control, col.GetHelp()); break; default: do { if (m_customCtrl != null) { break; } m_autoCompleteData = m_tblInfo.m_cols[CurrentCell.ColumnIndex].m_lookupData; if (m_autoCompleteData == null) { break; } AutoCompleteStringCollection coll = m_autoCompleteData.m_colls; DataGridViewTextBoxEditingControl edt = (DataGridViewTextBoxEditingControl)e.Control; edt.AutoCompleteMode = AutoCompleteMode.SuggestAppend; edt.AutoCompleteSource = AutoCompleteSource.CustomSource; edt.AutoCompleteCustomSource = coll; edt.Validated += Edt_Validated; } while (false); break; } }