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 (2) | Post RSS RSS comment feed

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

Related posts

Comments

11/9/2008 11:45:37 PM Permalink

Pingback from mgalinks.wordpress.com

2008 November 10 - Links for today « My (almost) Daily Links

mgalinks.wordpress.com |

11/11/2008 9:25:14 AM Permalink

Trackback from Community Blogs

Silverlight Cream for November 11, 2008 -- #424

Community Blogs |

Comments are closed

This site was built with the Sueetie .NET Open Source Community Framework. Learn more about Sueetie at Sueetie.com.