Telerik RadControls for Windows Phone – Article #7 – Using Custom Objects in RadAutoCompleteBox

In one of my earlier blog post , i explained about RadAutoCompleteBox showing how to display suggestions using a List of string .

I had a requirement to bind custom object to the Suggestion List to the RadAutoCompleteBox and had to take help of the Telerik Support Team to get it done.

To put it simple , Telerik’s Support Team is simply super .

To bind the Custom Business Objects , you should follow 3 steps

1. Set the SuggestionsSource to the List of Custom Objects

2. Set the FilterKeyPath

3. Create SuggestionItemTemplate and DataTemplate and bind the property that should be displayed as suggestion.

Below is a sample sourcecode that uses Custom Objects to display Suggestion .

<telerikInput:RadAutoCompleteBox Height="70" HorizontalAlignment="Left" Margin="17,31,0,0" Name="radAutoCompleteBox1" Text="" 
VerticalAlignment="Top" Width="429" FilterKeyPath="Name"  >
<telerikInput:RadAutoCompleteBox.SuggestionItemTemplate>
<DataTemplate>                     
<TextBlock Text="{Binding Name}"/>                 
</DataTemplate>                 
</telerikInput:RadAutoCompleteBox.SuggestionItemTemplate>             
</telerikInput:RadAutoCompleteBox>
public partial class MainPage : PhoneApplicationPage     
{         
// Constructor         
public MainPage()         
{             
InitializeComponent();             
radAutoCompleteBox1.SuggestionsSource = Data.GetSuggestions();         
}      
}     
public class Employee     
{         
public string Name         
{             
get;             
set;         
}

public string ID         
{             
get;             
set;         
}

}     
public static class Data     
{         
public static List<Employee> GetSuggestions()         
{             
List<Employee> Names = new List<Employee>();             
Names.Add(new Employee { Name = "Vijay", ID = "1" });             
Names.Add(new Employee { Name = "Senthil", ID = "2" });             
Names.Add(new Employee { Name = "Surya", ID = "3" });             
Names.Add(new Employee { Name = "Norton", ID = "4" });             
Names.Add(new Employee { Name = "Sandy", ID = "5" });             
Names.Add(new Employee { Name = "Saravan", ID = "6" });             
Names.Add(new Employee { Name = "Sunil", ID = "7" });            
 return Names;         
}     
}
Telerik RadControls for Windows Phone – Article #7 – Using Custom Objects in RadAutoCompleteBox
Telerik RadControls for Windows Phone – Article #7 – Using Custom Objects in RadAutoCompleteBox

Leave A Reply

Your email address will not be published. Required fields are marked *

You May Also Like

In this post, you’ll learn about the Win32 Error “0x000019E5 – ERROR_COULD_NOT_RESIZE_LOG” that you get when debugging system erors in...
In this post, you’ll learn about the error “CO_E_DBERROR 0x8004E02B” that is returned when working with COM based APIs or...
In this post, you’ll learn about the Win32 Error “0x000019D0 – ERROR_LOG_BLOCK_VERSION” that you get when debugging system erors in...