Populating Items

8 Mar 20182 minutes to read

SfAutoComplete control, supports binding to different data sources such as IList Data Source, Observable Collection Data Source.

Through AutoComplete Source Item

  • The AutoCompleteSource property in the SfAutoComplete control is used to set the list of strings to the suggestions dropdown.

  • To create a Text Box that automatically completes input strings by comparing the prefix being entered to the prefixes of all strings in a maintained source. This is useful for Text Box controls in which URLs, addresses, file names, or commands will be frequently entered.

NSMutableArray countryList=new NSMutableArray();

Through Binding

DataSource is a collection of SfAutoComplete items which is capable of holding any objects and displays the items based on the provided DisplayMemberPath value.

To populate items using data source, create a model class with the properties that to be bound.

public class Student
string Name;
string Age;
public Student(string name,string age)
this.Name = name;
this.Age = age;

public string getName()
return Name;
public string getAge()
return Age;
  • Create Student collection using Student class and assign the collection to DataSource property of SfAutoComplete
public NSMutableArray StudentDetails

void GetStudentData()
NSMutableArray array = new NSMutableArray();
array.Add(getDictionary("John", "24"));
array.Add(getDictionary("James", "37"));

StudentDetails = array;

NSDictionary getDictionary(string name, string age)

object[] objects = new object[2];
object[] keys = new object[2];
keys.SetValue("Name", 0);
keys.SetValue("Age", 1);
objects.SetValue((NSString)name, 0);
objects.SetValue((NSString)age, 1);
return NSDictionary.FromObjectsAndKeys(objects, keys);
  • Here student collection has two properties so we should tell the control, by which property, it has to provide suggestions. In this case, let us make the control to provide suggestions based on Name.
studentAutoComplete= new SfAutoComplete();
studentAutoComplete.DataSource = StudentDetails;
studentAutoComplete.DisplayMemberPath = "Name";
studentAutoComplete.SelectedValuePath = "Age";
  • DisplayMemberPath decides the suggestions to be shown in dropdown. Setting the SelectedValuePath property will make SelectedValue property to return the value you have selected here.