Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Made some sample code that might help - you can use as a guide.</p> <p>The idea is to handle the <code>TextChanged</code> event of the <code>ComboBox</code>, and really just modify the <code>ComboBox list items</code> at that point. The example below will modify the list to add the current text (most important, as this will not change the text when you click the combobox) and any other items that meet the search criteria.</p> <p>I don't think you need the code to re-initialize the list items when focus is lost, but left in there just in case.</p> <pre><code> //contains a list of default items for the combobox items List&lt;string&gt; comboList = new List&lt;string&gt;(); public Form1() { InitializeComponent(); initComboList(); //initialize the defaults initCombobox(); //initialize the combobox list items } //fills the defaults for the combobox items private void initComboList() { comboList.Add("red"); comboList.Add("blue"); comboList.Add("green"); } //initializes the combobox items private void initCombobox() { comboBox1.Items.Clear(); foreach (string s in comboList) comboBox1.Items.Add(s); } //occurs when the text changes in the combobox private void comboBox1_TextChanged(object sender, EventArgs e) { string curtext = comboBox1.Text; insertIntoComboBox(curtext); //insert the current text into combobox comboBox1.Select(curtext.Length, 0); //if you don't do this, the cursor goes back to index 0 :-( } //called whenever is desired to insert the current text into the combobox items private void insertIntoComboBox(string curtext) { comboBox1.Items.Clear(); //only add the current text if it's not already in the list of defaults and not empty string if (comboList.Contains(curtext) == false &amp;&amp; curtext.Length &gt; 0) comboBox1.Items.Add(curtext); foreach (string s in comboList) comboBox1.Items.Add(s); } //called whenever combobox loses focus private void comboBox1_Leave(object sender, EventArgs e) { initCombobox(); } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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