How to enable AutoComplete in a GridViewComboBoxColumn

13 posts, 0 answers
  1. Tarun
    Tarun avatar
    16 posts
    Member since:
    Jan 2011

    Posted 30 Aug 2011 Link to this post

    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>
  2. Maya
    Admin
    Maya avatar
    4062 posts

    Posted 31 Aug 2011 Link to this post

    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 >>

  3. UI for WPF is Visual Studio 2017 Ready
  4. Tarun
    Tarun avatar
    16 posts
    Member since:
    Jan 2011

    Posted 31 Aug 2011 Link to this post

    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.
  5. Maya
    Admin
    Maya avatar
    4062 posts

    Posted 31 Aug 2011 Link to this post

    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 >>

  6. Tarun
    Tarun avatar
    16 posts
    Member since:
    Jan 2011

    Posted 01 Sep 2011 Link to this post

    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"/>
  7. Maya
    Admin
    Maya avatar
    4062 posts

    Posted 01 Sep 2011 Link to this post

    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 >>

  8. Tarun
    Tarun avatar
    16 posts
    Member since:
    Jan 2011

    Posted 01 Sep 2011 Link to this post

    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 ?

  9. Maya
    Admin
    Maya avatar
    4062 posts

    Posted 02 Sep 2011 Link to this post

    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 >>

  10. Tarun
    Tarun avatar
    16 posts
    Member since:
    Jan 2011

    Posted 02 Sep 2011 Link to this post

    Maya, If you comment out the ToString property in the Club.cs , the autocomplete stops working. this seems like a bug.




  11. Maya
    Admin
    Maya avatar
    4062 posts

    Posted 03 Sep 2011 Link to this post

    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 >>

  12. Lawrence
    Lawrence avatar
    10 posts
    Member since:
    Jul 2013

    Posted 07 Jun Link to this post

    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
    }

  13. Maya
    Admin
    Maya avatar
    4062 posts

    Posted 08 Jun Link to this post

    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.
  14. Lawrence
    Lawrence avatar
    10 posts
    Member since:
    Jul 2013

    Posted 08 Jun in reply to Maya Link to this post

    Glad to help...thanks!
Back to Top
UI for WPF is Visual Studio 2017 Ready