This is a migrated thread and some comments may be shown as answers.

How to enable AutoComplete in a GridViewComboBoxColumn

12 Answers 554 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Tarun
Top achievements
Rank 1
Tarun asked on 30 Aug 2011, 11:01 PM
I have a GridViewComboBoxColumn. I have templated it as show below. I want that when users start typing a letter, the combo box takes them to the closest selection from its itemsource. Please advise.

<telerik:GridViewComboBoxColumn Header="To" DataMemberBinding="{Binding ToWireIns}" ItemsSource="{Binding WireInsCollection}" Width="150"
                                SelectedValueMemberPath="WireInsId"
                                Background="AntiqueWhite" IsComboBoxEditable="True">
    <telerik:GridViewComboBoxColumn.ItemTemplate>
        <DataTemplate>
            <StackPanel Orientation="Horizontal" HorizontalAlignment="Left" >
                <TextBlock Text="{Binding CustodianCode}" Width="50" />
                <TextBlock Text="{Binding AccountCode}" Width="40"/>
            </StackPanel>
        </DataTemplate>
    </telerik:GridViewComboBoxColumn.ItemTemplate>
</telerik:GridViewComboBoxColumn>

12 Answers, 1 is accepted

Sort by
0
Maya
Telerik team
answered on 31 Aug 2011, 06:54 AM
Hi Tarun,

You may set the IsComboBoxEditable property of the column. Thus you will be able to edit the combo box and the autocomplete functionality will be turned on.
 

Regards,
Maya
the Telerik team

Thank you for being the most amazing .NET community! Your unfailing support is what helps us charge forward! We'd appreciate your vote for Telerik in this year's DevProConnections Awards. We are competing in mind-blowing 20 categories and every vote counts! VOTE for Telerik NOW >>

0
Tarun
Top achievements
Rank 1
answered on 31 Aug 2011, 01:37 PM
Maya, if you look at the code i posted, IsComboBoxEditable is set to true. Despite that, when i start typing in the combo box, the drop down section does not open up and the selection does not go to what i have been typing.
0
Maya
Telerik team
answered on 31 Aug 2011, 01:45 PM
Hello Tarun,

Indeed, it was my mistake as I do not notice the mentioned property set. Please excuse me for that. Still, the autocomplete functionality of the combo box is not to open the drop down and select the item, but rather find it directly in the editable part of it.
Please take a look at this demo and test the feature (you may test it in the first RadComboBox).
 

All the best,
Maya
the Telerik team

Thank you for being the most amazing .NET community! Your unfailing support is what helps us charge forward! We'd appreciate your vote for Telerik in this year's DevProConnections Awards. We are competing in mind-blowing 20 categories and every vote counts! VOTE for Telerik NOW >>

0
Tarun
Top achievements
Rank 1
answered on 01 Sep 2011, 04:29 PM
Maya, The autocomplete is working in the RadComboBox but not in the GridViewComboBoxColumn . I have both controls hooked up simultaneously to make sure all bindings are working.

I have attached both pieces of code. Can you help figure out why it won't work in the GridViewComboBoxColumn

Autocomplete Working
<telerik:RadComboBox ItemsSource="{Binding WireInsCollection}" Width="185" Height="50"
                     ItemTemplate="{StaticResource ComboBoxCustomTemplate}"
                    telerik:TextSearch.TextPath="CustodianCode"/>

Autocomplete Not Working

<telerik:GridViewComboBoxColumn Header="From" DataMemberBinding="{Binding FromWireIns}" ItemsSource="{Binding WireInsCollection}" Width="185"
                                Background="AntiqueWhite" ItemTemplate="{StaticResource ComboBoxCustomTemplate}"
                                SelectedValueMemberPath="WireInsId"
                                telerik:TextSearch.TextPath="CustodianCode"/>
0
Maya
Telerik team
answered on 01 Sep 2011, 04:54 PM
Hello Tarun,

Please take a look at the sample project for a reference. May you check whether it corresponds to your settings and requirements ?
 

All the best,
Maya
the Telerik team

Thank you for being the most amazing .NET community! Your unfailing support is what helps us charge forward! We'd appreciate your vote for Telerik in this year's DevProConnections Awards. We are competing in mind-blowing 20 categories and every vote counts! VOTE for Telerik NOW >>

0
Tarun
Top achievements
Rank 1
answered on 01 Sep 2011, 05:17 PM
Hi Maya,

Using the same settings as the sample project, my GridViewComboBoxColumn does not autocomplete. I see that the version of Telerik.Windows.Controls dll in my project is 2011.2.712.35 whereas the version of Telerik.Windows.Controls dll in your sample project is 2011.2.712.40. Do you think this could be the reason ?

0
Maya
Telerik team
answered on 02 Sep 2011, 09:20 AM
Hi Tarun,

I have tested the project targeting WPF 3.5 with the binaries from 2011.2.712.35. Still, the behavior is the same. I am attaching the updated project. Can you reproduce the issue on this project ? 

 

Kind regards,
Maya
the Telerik team

Thank you for being the most amazing .NET community! Your unfailing support is what helps us charge forward! We'd appreciate your vote for Telerik in this year's DevProConnections Awards. We are competing in mind-blowing 20 categories and every vote counts! VOTE for Telerik NOW >>

0
Tarun
Top achievements
Rank 1
answered on 02 Sep 2011, 09:13 PM
Maya, If you comment out the ToString property in the Club.cs , the autocomplete stops working. this seems like a bug.




0
Maya
Telerik team
answered on 03 Sep 2011, 08:35 AM
Hello Tarun,

Actually, this is the expected behavior. If you do not override the ToString() method, you will get the whole object displayed, while editing. Consequently, you will not able to do the search based on the value of the corresponding property.
 

Regards,
Maya
the Telerik team

Thank you for being the most amazing .NET community! Your unfailing support is what helps us charge forward! We'd appreciate your vote for Telerik in this year's DevProConnections Awards. We are competing in mind-blowing 20 categories and every vote counts! VOTE for Telerik NOW >>

0
Lawrence
Top achievements
Rank 2
Iron
answered on 07 Jun 2016, 02:59 PM

I created my own Column type...

public class SearchableComboBoxColumn : GridViewBoundColumnBase
{
    #region Members
 
    public static readonly DependencyProperty DisplayMemberPathProperty =
        DependencyProperty.Register("DisplayMemberPathValue", typeof(string), typeof(SearchableComboBoxColumn));
 
    public static readonly DependencyProperty ItemSourceProperty =
        DependencyProperty.Register("ItemsSource", typeof(IEnumerable<object>), typeof(SearchableComboBoxColumn));
 
    public static readonly DependencyProperty SelectedValueMemberPathProperty =
                DependencyProperty.Register("SelectedValueMemberPath", typeof(string), typeof(SearchableComboBoxColumn));
 
    #endregion
 
    #region Properties
 
    /// <summary>
    /// Gets or sets the display member path.
    /// </summary>
    /// <value>
    /// The display member path.
    /// </value>
    public string DisplayMemberPath
    {
        get { return (string) GetValue(DisplayMemberPathProperty); }
        set { SetValue(DisplayMemberPathProperty, value); }
    }
 
    /// <summary>
    /// Gets or sets the items source.
    /// </summary>
    /// <value>
    /// The items source.
    /// </value>
    public IEnumerable<object> ItemsSource
    {
        get { return (IEnumerable<object>) GetValue(ItemSourceProperty); }
        set { SetValue(ItemSourceProperty, value); }
    }
 
    /// <summary>
    /// Gets or sets the selected value member path.
    /// </summary>
    /// <value>
    /// The selected value member path.
    /// </value>
    public string SelectedValueMemberPath
    {
        get { return (string) GetValue(SelectedValueMemberPathProperty); }
        set { SetValue(SelectedValueMemberPathProperty, value); }
    }
 
    #endregion
 
    #region Public Methods
 
    /// <summary>
    /// Creates the element for the cell in edit mode.
    /// </summary>
    /// <param name="cell"></param>
    /// <param name="dataItem"></param>
    /// <returns></returns>
    public override FrameworkElement CreateCellEditElement(GridViewCell cell, object dataItem)
    {
        cell.HorizontalContentAlignment = HorizontalAlignment.Stretch;
        this.BindingTarget = System.Windows.Controls.Primitives.Selector.SelectedValueProperty;
 
        var comboBox = new RadComboBox
        {
            HorizontalAlignment = HorizontalAlignment.Stretch,
            ItemsSource = this.ItemsSource,
            IsTextSearchEnabled = true,
            IsTextSearchCaseSensitive = false,
            StaysOpenOnEdit = true,
            IsEditable = true,
            IsFilteringEnabled = true,
            TextSearchMode = TextSearchMode.Contains,
            SelectedValuePath = this.SelectedValueMemberPath,
            DisplayMemberPath = this.DisplayMemberPath,
            Text = this.GetText(dataItem)
        };
 
        comboBox.SetBinding(this.BindingTarget, new Binding
        {
            Mode = BindingMode.TwoWay,
            Path = new PropertyPath(this.DataMemberBinding.Path.Path)
        });
 
        return comboBox;
    }
 
    /// <summary>
    /// </summary>
    /// <param name="cell"></param>
    /// <param name="dataItem"></param>
    /// <returns></returns>
    /// <inheritdoc />
    public override FrameworkElement CreateCellElement(GridViewCell cell, object dataItem)
    {
        cell.HorizontalContentAlignment = HorizontalAlignment.Stretch;
        return new TextBlock
        {
            HorizontalAlignment = HorizontalAlignment.Stretch,
            Text = this.GetText(dataItem)
        };
    }
 
    #endregion
 
    #region Private Methods
 
    /// <summary>
    /// Gets the text.
    /// </summary>
    /// <param name="dataItem">The data item.</param>
    /// <returns></returns>
    private string GetText(object dataItem)
    {
        Type type = dataItem.GetType();
        PropertyInfo property = new List<PropertyInfo>(type.GetProperties()).Single(p => p.Name.Equals(this.DataMemberBinding.Path.Path));
        object identifier = property.GetValue(dataItem);
        object value = this.ItemsSource.SingleOrDefault(x => x.GetType().GetProperty(this.SelectedValueMemberPath).GetValue(x).Equals(identifier));
 
        return value?.GetType().GetProperty(this.DisplayMemberPath).GetValue(value).ToString();
    }
 
    #endregion
}

0
Maya
Telerik team
answered on 08 Jun 2016, 02:00 PM
Hello Lawrence,

That's great. Thanks a lot for sharing it with the community.

Regards,
Maya
Telerik
Do you need help with upgrading your AJAX, WPF or WinForms project? Check the Telerik API Analyzer and share your thoughts.
0
Lawrence
Top achievements
Rank 2
Iron
answered on 08 Jun 2016, 04:35 PM
Glad to help...thanks!
Tags
GridView
Asked by
Tarun
Top achievements
Rank 1
Answers by
Maya
Telerik team
Tarun
Top achievements
Rank 1
Lawrence
Top achievements
Rank 2
Iron
Share this question
or