SfComboBox editable

Hi folks,

How can I achieve to manually write some text in SfComboBox? I need user write some text in a SfComboBox and save it to a list.

Please can you help me?

Cheers

3 Replies

SK Senthil Kumaran Rajan Syncfusion Team September 3, 2018 12:35 PM UTC

Hi Josep, 
 
Thank you for contacting Syncfusion support. 
 
To add the newly typed text as SfComboBoxItem in the SfComboBox , you can handled it using the KeyDown event. In our sample , we have fetch the text which has been typed in the SfComboBox using VisualTreeHelper and added into existing collection of SfComboBox in KeyDown event. Please find the code for the same from below: 
 
Code Behind: [C#] 
 
private void combobox_KeyDown(object sender, KeyRoutedEventArgs e) 
        { 
            if (e.Key == Windows.System.VirtualKey.Enter) 
            { 
                if (!string.IsNullOrEmpty(textboxext.Text)) 
                { 
                    bool itemexist = false; 
                    CountryList item = new CountryList() { Name = textboxext.Text }; 
                    foreach (CountryList item1 in Countries) 
                    { 
                        if (item1.Name == item.Name) 
                        { 
                            itemexist = true; 
                            break; 
                        } 
                    } 
                    if (!itemexist) 
                    { 
                        textboxext.Text = item.Name; 
                        sfComboBox.SelectedValue = textboxext.Text; 
                        countries.Add(item); 
                    } 
                } 
            } 
        } 
 
We have prepared the sample for your reference and this can be downloaded from the below location.  
 
  
Regards 
Senthil 



JO josep September 3, 2018 12:38 PM UTC

Ok. Thanks for your update


SK Senthil Kumaran Rajan Syncfusion Team September 3, 2018 01:04 PM UTC

Hi Josep, 
 
Thank you for your update. 
 
Please let us know if you need further assistance, we will be happy to assist you. 
 
Regards, 
Senthil 


Loader.
Up arrow icon