We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. (Last updated on: June 24, 2019).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

Add Item at runtime

Thread ID:

Created:

Updated:

Platform:

Replies:

149384 Nov 24,2019 08:27 PM UTC Dec 2,2019 06:21 AM UTC Xamarin.Forms 7
loading
Tags: SfAutoComplete
Marco Salvatori
Asked On November 24, 2019 08:27 PM UTC

Hi, it is possible to insert an item not included in the list (DataSource) and at the same time update the list (DataSource).
thanks.

Hemalatha Marikumar [Syncfusion]
Replied On November 25, 2019 12:04 PM UTC

Hi Marco,

Greetings from Syncfusion.
 
 
Query: Is  it possible to insert an item not included in the list (DataSource) and at the same time update the list (DataSource). 
 
Yes. It is possible to insert the items (either with collection of string or collection of custom class with DataSource property of SfAutoComplete) as per in below code snippet. Here we have demonstrated this dynamic update functionality in two ways 
 
·       Dynamically insert the typed text in the Entry to the first loaded SfAutocomplete 
 
    private void Entry_Completed(object sender, EventArgs e) 
        { 
            voltage.VoltageCollection.Insert(0,(sender as Entry).Text); 
        }

 
 
 
·       Dynamically insert the custom class to the custom class collection of SfAutoComplete through the button click as per in below code snippet 
 
private void Button_click(object sender, EventArgs e) 
        { 
            voltage.VoltageCollectionModel.Insert(0, new VoltageModel() { Value = "ItemCollection", ID = 2 }); 
        } 
Please check with the above and let us know if you have any concerns. 
 
Regards, 
Hemalatha M. 
 


Marco Salvatori
Replied On November 25, 2019 02:28 PM UTC

Hi,
I wanted to do it without using a text field. Directly inside the autocomplete control. For example when I use the return ...

code like this:

autoCompleteViewModel.EmployeeCollection.Add(new Employee() { ID = 10, Name = autoCompleteXAML.Text });
autoCompleteXAML.insert(new Item {text = autoCompleteXAML.Text });

Thanks

Hemalatha Marikumar [Syncfusion]
Replied On November 26, 2019 12:07 PM UTC

Hi Marco,

Thanks for your update.

Query 1: I wanted to do it without using a text field.
 
( autoCompleteViewModel.EmployeeCollection.Add(new Employee() { ID = 10, Name = autoCompleteXAML.Text });) 
 
We have analyzed your requirement in SfAutoComplete. We have checked possibility of where we have added the new items to the EmployeeCollection.  First, we have tried to use ValueChanged event of SfAutoComplete. In that for every text changed on SfAutoComplete, it will be invoked. Hence moved to Completed event, it will invoke once pressed the Enter button. With this, typed text has been added to the EmployeeCollection as per in below code snippet and it has been worked fine 
  
Code Snippet[C#]: 
        private void AutoComplete_Completed(object sender, EventArgs e) 
        { 
            employeeViewModel.EmployeeCollection.Add(new Employee() { Name = autoComplete.Text, ID = employeeViewModel.EmployeeCollection.Count() }); 
        } 
  
Sample Link: 
Query 2: autoCompleteXAML.insert(new Item {text = autoCompleteXAML.Text }); 
  
We have analyzed your requirement from the provided code snippet. And it seems like you have directly insert the SfAutoComplete’s text to its. Since autoCompleteXAML is instance of SfAutoComplete. It is not possible to insert the new data directly to the control. The data populated has been implemented with the dropdown not with the control.  
 
Please check with above let us know if you have any other queries. 
 
Regards, 
Hemalatha M. 


Marco Salvatori
Replied On November 27, 2019 02:04 PM UTC

I would like something like the two attached images.
Type the new string (img 1), and when I press return, it automatically updates the control as in the other image (img 3).
I couldn't ...

Regards

Attachment: autocomplete_60ec9bcb.zip

Hemalatha Marikumar [Syncfusion]
Replied On November 28, 2019 04:47 PM UTC

Hi Marco 
 
Thanks for clarifying your requirement. 
 
We would like to let you know that currently we are facing the difficulty to achieve your requirement with SfAutoComplete since there is some dependent property updates with DataSource and SelectedItem with Token mode. But your requirement “Typed text should change as Token” has been achieved by using SfChipGroup control with its default mode of Input. 
 
To know more about this control, please refer the below UG 
 
 
 
 
 
InputView on SfChipGroup allows to add any editors’ controls. Here, using that typed text has been added to the ItemsSource of SfChipGroup to get the desired view as per in below code snippet 
 
CodeSnippet [XAML]: 
 
<SyncfusionButton:SfChipGroup  
                              
                            DisplayMemberPath="Name" 
                            ItemsSource="{Binding EmployeeCollection,Mode=TwoWay}" 
                            Type="Input" 
                            ..> 
            <SyncfusionButton:SfChipGroup.InputView> 
                <Entry Completed="Entry_Completed" 
                            VerticalOptions="Center"  
                            FontSize="15"  
                            WidthRequest="110"  
                            Margin="10,10,0,0"> 
                         
                    </Entry> 
            </SyncfusionButton:SfChipGroup.InputView> 
</SyncfusionButton:SfChipGroup> 
 
 
CodeSnippet [C#]: 
 
private void Entry_Completed(object sender, EventArgs e) 
        { 
            Entry entry = sender as Entry; 
            if (entry != null && !string.IsNullOrEmpty(entry.Text)) 
            { 
                viewModel.EmployeeCollection.Add(new Employee() { Name = entry.Text, ID = 1 }); 
            } 
 
            entry.Text = string.Empty; 
        } 
 
 
Screenshots: 
 
 
 
Please download the prepared sample and captured video while testing the sample 
 
 
 
Please let us know whether your requirement has been achieved by the above one if not please revert us with more details like whether you are also need the drop-down to show the suggestion as per in SfAutoComplete. 
 
Regards, 
Hemalatha M. 


Marco Salvatori
Replied On November 29, 2019 04:08 PM UTC

good...very good....
thanks

Hemalatha Marikumar [Syncfusion]
Replied On December 2, 2019 06:21 AM UTC

Hi Macro, 
 
Thanks for your update. 
 
We glad to hear that given solution works. 
 
Please let us know if you need any further assistance. 
 
Regards, 
Hemalatha M.  


CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

Please sign in to access our forum

This page will automatically be redirected to the sign-in page in 10 seconds.

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon

Live Chat Icon For mobile
Live Chat Icon