问题
i am currently displaying data in the radgrid controls of telerik, i want to add an autotextbox over the column named "Name". how can i do this?
my radgrid only displays data and i want that whenever user enters into textbox a list of name pops up just like in stackoverflow web site.
please help..i have been using silverlight,wcf ria services,telerik controls.
回答1:
You can use the AutoComplete textbox from the Silverlight 4 Toolkit. The toolkit is an advanced set of controls that are not part of the core Visual Studio library. To download & install, you can head here. Once you have it installed, you add a project reference to System.Windows.Controls add this to your UserControl declaration:
xmlns:input="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Input"
This gives you a reference point for the Silverlight Toolkit, specifically the input controls. Once that's done, here is an example of using the autocomplete textbox:
<input:AutoCompleteBox IsTextCompletionEnabled="False" HorizontalAlignment="Left" ItemsSource="{StaticResource SampleEmployees}" SelectionChanged="OnSelectionChanged"/>
This comes directly from the documentation from the Silverlight Toolkit. Link here. Click the 'AutoCompleteBox' in the left menu (under heading: Input). Once loaded, you can view the XAML/C# by clicking on any one of the items at the bottom of the window, such as 'AutoCompleteBoxSample.xaml' or 'AutoCompleteBoxSample.xaml.cs' This should give you the start/code you're looking for.
In your case, you'll also need to create a cell template for the radgridview. Here's a quick sample of what that might look like:
<radControls:RadGridView x:Name="registerGridView"
AutoGenerateColumns="False">
<radControls:RadGridView.Columns>
<radControls:GridViewToggleRowDetailsColumn />
<radControls:GridViewDataColumn Header="Client" />
<radControls:GridViewDataColumn Header="Site" />
<radControls:GridViewDataColumn Header="Name">
<radControls:GridViewDataColumn.CellTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal">
<input:AutoCompleteBox HorizontalAlignment="Left" ItemsSource="{Binding Names}" SelectionChanged="OnSelectionChanged"/>
</StackPanel>
</DataTemplate>
</radControls:GridViewDataColumn.CellTemplate>
</radControls:GridViewDataColumn>
</radControls:RadGridView.Columns>
</radControls:RadGridView>
来源:https://stackoverflow.com/questions/5871918/using-autocomplete-box-in-silverlight