Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>I'm answering my own question because I've implemented my own solution to this by using custom control.</p> <p>This custom control is created by keeping a textbox above combo box in such a way that only drop down button of combobox is visible.</p> <p>Now I've created a custom column in datagridview deriving the DataGridViewEditingControl from my usercontrol.</p> <p>I've added a property in Usercontrol which will take drop down list source from the control which is hosting datagridview. </p> <p>Now in the EditingControlShowing event I'm setting this property as below</p> <pre><code>private void dataGridView2_EditingControlShowing(object sender, DataGridViewEditingControlShowingEventArgs e) { if(dataGridView2.CurrentCell.ColumnIndex.Equals(0) &amp;&amp; e.Control is UserControl1) { var uscontrol = e.Control as UserControl1; uscontrol.DropDownListSource = source; } } </code></pre> <p>This drop down list source is used in the usercontrol to set the autocompletesource to the textbox and datasource to the combobox as below: Whenever I set the DropDownDataSource I'm firing an event in the usercontrol which will do the following. This is to ensure that every time EditingControlShowing event occurs for this column in DataGridView, this source is updated for textbox and combobox in usercontrol.</p> <pre><code>private void DropDownSourceChanged(object sender, EventArgs eventArgs) { textBox1.AutoCompleteCustomSource = DropDownListSource; textBox1.AutoCompleteMode = AutoCompleteMode.SuggestAppend; textBox1.AutoCompleteSource = AutoCompleteSource.CustomSource; comboBox1.DataSource = DropDownListSource; } </code></pre> <p>Now whenever user starts typing in the textbox autocomplete source will display dropdown list with 'NameWithCode' values and if user selects one of them then I'll set it to the Text propery overidden in my usercontrol which will be used for the cell value in the DataGridView. Now based on the Textbox text (which is NameWithCode) I can get the code part and set it to the text property. If user uses combobox dropdown button to select the item then I'll get the combobox selected text and set it in the Textbox which is ultimately used by the cell for getting value.</p> <p>This way I could achieve the solution I want.</p> <p>@Homam, solution also works but when I change the ComboBox's DropDownStyle to allow the user to type the value in the combobox it behaves weirdly and not getting up to the mark solution for my requirement. Hence I used this solution.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload