Skip to main content
Home Forums Silverlight Programming Silverlight Controls and Silverlight Toolkit Programmatically show/activate autocompletebox dropdown
4 replies. Latest Post by jwilcox on January 20, 2009.
(0)
KaptajnVom
Member
5 points
8 Posts
01-05-2009 10:08 AM |
Is it possible to programmatically show/activate the dropdown used by a autocompletebox control?
I aim at having the autocompletebox show all items in a list without the user typing a filter.
For example doing:
...acb.IsTextCompletionEnabled = true;acb.SearchMode = AutoCompleteSearchMode.Contains;acb.ItemsSource = myStringArray;acb.Text = "z";
In the above case I would like to show the dropdown with all strings containing "z" from myStringArray.
Best Regards,Thomas Hagen
jwilcox
Participant
1082 points
187 Posts
01-05-2009 11:42 AM |
Thomas,
Technically the auto complete control does not expose a method for doing this, but if you look through the unit tests that came with the toolkit (AutoCompleteBoxTest.cs), you'll see that those do exactly what you are looking to do.
The process is:
1. Step into the visual tree to find the TextBox that is part of the auto complete control
2. Programatically set the Text dependency property value on the TextBox (not auto complete box) to your value ("z")
That should work just fine. Let me know if you need help locating the test or getting this working.
-Jeff
01-06-2009 11:01 AM |
Thanks Jeff.
For future readers/reference:
1. The VisualTree must be traversed after the control has Loaded - otherwise you risk that Textbox is not created (== null)
2. The flesh of the code is:void AutoCompleteBox_Loaded(object sender, RoutedEventArgs e){ DependencyObject o = VisualTreeHelper.GetChild((AutoCompleteBox)sender, 0); o = VisualTreeHelper.GetChild(o,0); ((TextBox)(o)).Text = "z";}
mikejos
2 points
7 Posts
01-20-2009 2:33 AM |
Additionally, is there a way to programmatically select and display an item from the autocompletebox ItemsSource?
I want to use the same control, an AutoCompleteBox, both for searching and displaying data.
01-20-2009 5:35 AM |
@mikeros,
If you're simply looking to set the SelectedItem, or use a two-way binding, the next release of the toolkit will support this. In the meantime, you can get early access to the changes here: http://www.jeff.wilcox.name/2008/12/selecteditem-dcr/