Dave Burke : Freelance .NET Web Developer specializing in Online Communities

Silverlite: Why your AutoCompleteBox may not be working

I downloaded the new Silverlight Toolkit from CodePlex and used the AutoCompleteBox control on my recent Silverlight Datagrid app.  It worked great, that is, after I struggled to figure out why it wasn't.

My problem was that I was replacing a ComboBox control with an AutoCompleteBox and was trying to bind a collection to the AutoCompleteBox the same way I was binding it to the ComboBox.

This is how I was binding a collection to my custom ComboBox in a PreparingCellForEdit event.


MyComboBox employeeList = (MyComboBox)dg.CurrentColumn.GetCellContent(e.Row);
employeeList.ItemsSource = employees;


See the problem with attempting to set the AutoCompleteBox's ItemsSource to employees, a collection of type JobEmployee?  Right.  AutoCompleteBox binds to an IEnumerable like a STRING list.  Think AutoCompleteBox = List of Strings.

AutoCompleteBox emps = (AutoCompleteBox)dg.CurrentColumn.GetCellContent(e.Row);
var empString = (from c in employees
         select c.EmployeeName);

emps.ItemsSource = empString;
emps.Focus();


Thanks to this Tim Heuer post on using AutoCompleteBox with custom types that showed me the light.

Comments (0) | Post RSS RSS comment feed

Posted on 11/9/2008 3:13:44 PM by Dave Burke
Categories: .NET | Silverlight
Tags:

Related posts

Pingbacks and trackbacks (3)+


Powered by BlogEngine.NET 2.0.0.36
Theme by Dave Burke