data binding - Winforms, Combobox, Databinding... allow user to type in a value not found in the DataSource -


Says the same as the title ... I have a winform application with a database dropdown. I want the user to have the option of choosing from a bunch of predefined values, but the ability to type in their own value also

If I enable the database and leave anything dropdown type But dropdown list gives it, so I have to enter anything that I want but it does not carry items ... It seems that ... to solve a simple Credit problems ... help?

I've added an event handler to ComboBox.Leave , this code is built-in With the list (the countries) will combine the newly typed string in the combobox, and will also refresh the binding Cambodia for it.

Limitations

  1. You have to add a new element based on your data source.
  2. List.Contains is case sensitive, you want to keep all the cases in one case. The user is changed in that case before deciding to add that data to the data source.

    Here you can go, modify comboBox1_Leave eventhandler according to your data and data source.

      Public Partial Class Form 1: Form {Private List & lt; String & gt; Countries; Public Form 1 () {Initialization (); } Private Zero form1_load (object sender, eventAgds E) {country = new list & lt; String & gt; (); Countries.Add ("Australia"); Countries.Add ("Belgium"); Countries.Add ("Canada"); ComboBox1.DataSource = Countries; } Private Zero comboBox1_Leave (Object Sender, EventArgs E) {COMBO BOX COMBO = (Sender as ComboBox); MudRamangar cm = (combo binding contact [combo. Datasource] as currency currency); If (! CM.List.Comp (combo. Text)) {SemiList.Add (combo. Text); Cm.EndCurrentEdit (); Cm.Refresh (); Cm.Position = CmCount - 1; }}}    

Comments