No Dropdown on focus & Suggest mode not working

23 posts, 0 answers
  1. Martin
    Martin avatar
    5 posts
    Member since:
    Nov 2010

    Posted 29 Oct 2012 Link to this post

    Hi,

    I am in the process of evaluating the Telerik controls for WPF.
    I was trying to get following functionality : a kind of dropdown list with autocomplete functionality where the list opens when the control gets the focus, and the list is filtered dynamically as soon as the user starts typing. When the control loses focus and the user has not yet selected an item, then the first item in the list should be selected.
    I have tried both autocompletebox and combobox, and in fact what I have in mind is a combination of both.
    In the case of an autocompletebox
     - I don't see the list on focus (the user has to type something)
     - when leaving the box (ie pressing enter or tab) the first item in the list is not selected
     - Suggest and SuggestAppend don't seem to work (and I don't see any difference between them), itemis not automatically selected
     - I don't see a way to restrict the text to items in the list
    In the case of a combobox :
     - I have no watermark text
     - the list does not shrink when typing (which makes "contains" mode not very useful)

    Kind regards,

    Martin
  2. Jc
    Jc avatar
    25 posts
    Member since:
    Sep 2012

    Posted 31 Oct 2012 Link to this post

    Hi guys,

    I'm using "RadControls for WPF Q3 2012" for a while, and I encounter the same problem:

    Is there any way to filter the RadComboBox values, and not only giving the focus to first found item, but also displaying only items containing the searched string?

    Or is there any way to get the AutocompleteBox drop down available values at user focus(in the case we've got only few items in the list, it's then a pain to find a first letter matching for the user experience)?

    Thanks for your help.
    JC
  3. UI for WPF is Visual Studio 2017 Ready
  4. Ivo
    Admin
    Ivo avatar
    390 posts

    Posted 01 Nov 2012 Link to this post

    Hi guys,

    Straight to your questions.
    • Displaying all the items on focus can be achieved by writing a little custom code. I prepared a sample project that demonstrates how this can be achieved. You can find it attached.
    • Pressing Tab or Enter selects the currently highlighted item into the dropdown portion of the control. If there is no currently highlighted item no item will be selected. However you can handle the key down event and select the first item from the drop down portion if there was no highlighted item. Here is sample code:
      private IEnumerable lastFilteredItems;
       
      private void RadAutoCompleteBox_KeyDown(object sender, KeyEventArgs e)
      {
          if (e.Key == Key.Tab && !e.Handled)
          {
              //e.Handled = false means that no item was selected with Tab key.
              var autoComplete = (RadAutoCompleteBox)sender;
              var itemToSelect = lastFilteredItems.OfType<object>().FirstOrDefault();
              autoComplete.SelectedItem = itemToSelect;
          }
      }
       
      private void RadAutoCompleteBox_Populated(object sender, EventArgs e)
      {
          var autoComplete = (RadAutoCompleteBox)sender;
          this.lastFilteredItems = autoComplete.FilteredItems;
      }
    • Using both Suggest and SuggestAppend modes doesn't highlight an item by default. The main difference between the two modes is into the append functionality when item is highlighted. You can find pictures that will make it more clear for you into our online help.
    • There is no such built in feature or easy way to implement this. We will do our best to provide a way to achieve this easily.

    • You can set the watermark text by using the EmtpyText property of the RadComboBox.
    • I guess the IsFilteringEnabled property will do the trick in this case. However have in mind that RadComboBox doesn't support filtering when using virtualized panel. This means that if you have a lot of items it would be best yo use the RadAutoCompleteBox.
    Greetings,
    Ivo
    the Telerik team

    Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

  5. Jc
    Jc avatar
    25 posts
    Member since:
    Sep 2012

    Posted 02 Nov 2012 Link to this post

    I've been implementing the  sample project's code and it works perfectly! :-)
    Thank's a lot.
    bye
  6. Martin
    Martin avatar
    5 posts
    Member since:
    Nov 2010

    Posted 07 Nov 2012 Link to this post

    Hi,

    sorry for the late response.
    Just tried it, and this is exactly what I want.
    Thanks alot !

    Martin
  7. Jonah
    Jonah avatar
    29 posts
    Member since:
    Oct 2012

    Posted 20 Dec 2012 Link to this post

    I tried this sample and can't seem to get it to work properly. If i type something in the box then remove the text I get the popup on focus but no before that. By trying this sample I mean I downloaded and ran the project you attached and that was the behavior. Was this the intended behavior or am I missing something?
  8. Martin
    Martin avatar
    5 posts
    Member since:
    Nov 2010

    Posted 21 Dec 2012 Link to this post

    Hi Jonah,

    I was having the same problem and was able to solve it by setting the IsDropDown property to false, just before calling the populate method in the GotFocus event handler :

    void RadAutoCompleteBox_GotFocus(object sender, System.Windows.RoutedEventArgs e)
    {
    	string searchText = this.SearchText;
    	if (this.SelectedItem != null)
    	{
    		searchText = BindingExpressionHelper.GetValue(this.SelectedItem, this.DisplayMemberPath).ToString();
    	}
    	this.IsDropDownOpen = false//ohterwise it doesn't work the first time with mouse
    this.Populate(searchText); }




    Kind regards,

    Martin
  9. Jonah
    Jonah avatar
    29 posts
    Member since:
    Oct 2012

    Posted 21 Dec 2012 Link to this post

    Thanks that worked great! However I still have one issue. When I use the FilteringBehavior I get another error object not set to an instance of an object. This is for an autocomplete that is inside a tab control, so each tab control will be given a list of items from the parent container and that list is the item source for the AC Box.There error is in the OnItemSourceChanged event of the AC Box


    Edit- Ended up going a different direction with this particular box but your suggestion worked great on my original project thanks again.
  10. Ivo
    Admin
    Ivo avatar
    390 posts

    Posted 02 Jan 2013 Link to this post

    Hi,

    There was an issue that prevented the RadAutoCompleteBox opening when getting the focus for the first time. It will be fixed into the next internal build.

    Jonaz, it would be great if you open a new support ticket describing the issue you have so we will be able to investigate it further.

    Regards,
    Ivo
    the Telerik team

    Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

  11. danparker276
    danparker276 avatar
    389 posts
    Member since:
    Aug 2010

    Posted 09 Jan 2013 Link to this post

    Is there a way I could add a button that would trigger the dropdown to open?

    Or if i set myACB.IsDropDownOpen = true in the code when focused, there is nothing in the dropdown, I have to put a space in there.  Is this something being fixed or by design.
  12. Ivo
    Admin
    Ivo avatar
    390 posts

    Posted 14 Jan 2013 Link to this post

    Hi,

    In order to achieve this you have to create a custom FilteringBehavior like the one mentioned below. I prepared a sample project and you can find it attached.

    Greetings,
    Ivo
    the Telerik team

    Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

  13. danparker276
    danparker276 avatar
    389 posts
    Member since:
    Aug 2010

    Posted 14 Jan 2013 Link to this post

    Thanks for the example, it worked great.  I'll just wait for the first time fix mentioned above and everything is perfect.
  14. Cameron
    Cameron avatar
    12 posts
    Member since:
    Jan 2013

    Posted 23 Jan 2013 Link to this post

    I am currently trying to implement this exact behaviour, but am getting a null reference exception when using the custom filtering behaviour bellow.

    As is, it works with no exception, (as it is just calling the base method), but if we uncomment the code, a null reference is thrown when we call window.Show() on the window containing the AutoCompleteBox.

    Here is the code causing the issue:

    public override IEnumerable<object> FindMatchingItems(string searchText, System.Collections.IList items, IEnumerable<object> escapedItems, string textSearchPath, TextSearchMode textSearchMode) {
     
                return base.FindMatchingItems(searchText, items, escapedItems, textSearchPath, textSearchMode);
     
                /*
                if (string.IsNullOrWhiteSpace(searchText)) {
                    return items.OfType<object>().Where(x => !escapedItems.Contains(x));
                } else {
                    return base.FindMatchingItems(searchText, items, escapedItems, textSearchPath, textSearchMode);
                }
                */
            }



    And here is the stack trace of the null exception:

    System.NullReferenceException was unhandled by user code
      Message=Object reference not set to an instance of an object.
      Source=Telerik.Windows.Controls.Input
      StackTrace:
           at Telerik.Windows.Controls.RadAutoCompleteBox.OpenDropDown() in c:\TB\102\WPF_Scrum\Release_WPF\Sources\Development\Controls\Input\AutoCompleteBox\RadAutoCompleteBox.cs:line 1192
           at Telerik.Windows.Controls.RadAutoCompleteBox.OnIsDropDownOpenChanged(Boolean isOpen) in c:\TB\102\WPF_Scrum\Release_WPF\Sources\Development\Controls\Input\AutoCompleteBox\RadAutoCompleteBox.cs:line 672
           at Telerik.Windows.Controls.RadAutoCompleteBox.OnIsDropDownOpenChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) in c:\TB\102\WPF_Scrum\Release_WPF\Sources\Development\Controls\Input\AutoCompleteBox\RadAutoCompleteBox.cs:line 879
           at System.Windows.DependencyObject.OnPropertyChanged(DependencyPropertyChangedEventArgs e)
           at System.Windows.FrameworkElement.OnPropertyChanged(DependencyPropertyChangedEventArgs e)
           at System.Windows.DependencyObject.NotifyPropertyChange(DependencyPropertyChangedEventArgs args)
           at System.Windows.DependencyObject.UpdateEffectiveValue(EntryIndex entryIndex, DependencyProperty dp, PropertyMetadata metadata, EffectiveValueEntry oldEntry, EffectiveValueEntry& newEntry, Boolean coerceWithDeferredReference, Boolean coerceWithCurrentValue, OperationType operationType)
           at System.Windows.DependencyObject.SetValueCommon(DependencyProperty dp, Object value, PropertyMetadata metadata, Boolean coerceWithDeferredReference, Boolean coerceWithCurrentValue, OperationType operationType, Boolean isInternal)
           at System.Windows.DependencyObject.SetValue(DependencyProperty dp, Object value)
           at Telerik.Windows.Controls.RadAutoCompleteBox.set_IsDropDownOpen(Boolean value) in c:\TB\102\WPF_Scrum\Release_WPF\Sources\Development\Controls\Input\AutoCompleteBox\RadAutoCompleteBox.cs:line 362
           at Telerik.Windows.Controls.Primitives.AutoCompleteHelper.InvalidateIsDropDownOpen() in c:\TB\102\WPF_Scrum\Release_WPF\Sources\Development\Controls\Input\AutoCompleteBox\AutocompleteHelper.cs:line 219
           at Telerik.Windows.Controls.Primitives.AutoCompleteHelper.Populate(String text) in c:\TB\102\WPF_Scrum\Release_WPF\Sources\Development\Controls\Input\AutoCompleteBox\AutocompleteHelper.cs:line 97
           at Telerik.Windows.Controls.RadAutoCompleteBox.OnItemsSourceChanged(Object newValue, Object oldValue) in c:\TB\102\WPF_Scrum\Release_WPF\Sources\Development\Controls\Input\AutoCompleteBox\RadAutoCompleteBox.cs:line 659
           at Telerik.Windows.Controls.RadAutoCompleteBox.OnItemsSourceChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) in c:\TB\102\WPF_Scrum\Release_WPF\Sources\Development\Controls\Input\AutoCompleteBox\RadAutoCompleteBox.cs:line 856
           at System.Windows.DependencyObject.OnPropertyChanged(DependencyPropertyChangedEventArgs e)
           at System.Windows.FrameworkElement.OnPropertyChanged(DependencyPropertyChangedEventArgs e)
           at System.Windows.DependencyObject.NotifyPropertyChange(DependencyPropertyChangedEventArgs args)
           at System.Windows.DependencyObject.UpdateEffectiveValue(EntryIndex entryIndex, DependencyProperty dp, PropertyMetadata metadata, EffectiveValueEntry oldEntry, EffectiveValueEntry& newEntry, Boolean coerceWithDeferredReference, Boolean coerceWithCurrentValue, OperationType operationType)
           at System.Windows.StyleHelper.ApplyTemplatedParentValue(DependencyObject container, FrameworkObject child, Int32 childIndex, FrugalStructList`1& childRecordFromChildIndex, DependencyProperty dp, FrameworkElementFactory templateRoot)
           at System.Windows.StyleHelper.InvalidatePropertiesOnTemplateNode(DependencyObject container, FrameworkObject child, Int32 childIndex, FrugalStructList`1& childRecordFromChildIndex, Boolean isDetach, FrameworkElementFactory templateRoot)
           at System.Windows.FrameworkTemplate.InvalidatePropertiesOnTemplate(DependencyObject container, Object currentObject)
           at System.Windows.FrameworkTemplate.HandleBeforeProperties(Object createdObject, DependencyObject& rootObject, DependencyObject container, FrameworkElement feContainer, INameScope nameScope)
           at System.Windows.FrameworkTemplate.<>c__DisplayClass6.<LoadOptimizedTemplateContent>b__3(Object sender, XamlObjectEventArgs args)
           at System.Xaml.XamlObjectWriter.OnBeforeProperties(Object value)
           at System.Xaml.XamlObjectWriter.Logic_CreateAndAssignToParentStart(ObjectWriterContext ctx)
           at System.Xaml.XamlObjectWriter.WriteEndObject()
           at System.Xaml.XamlWriter.WriteNode(XamlReader reader)
           at System.Windows.FrameworkTemplate.LoadTemplateXaml(XamlReader templateReader, XamlObjectWriter currentWriter)
      InnerException:


    I would love any advice on WHAT is causing the null reference, so we can hard code a value to it.

    EDIT: Adding to this, the samples posted all work perfectly, the only difference with our project is the AutoCompleteBox being placed on a new RadWindow, and the ItemSource being a list of strings (therefore not requiring a member path)
  15. Cameron
    Cameron avatar
    12 posts
    Member since:
    Jan 2013

    Posted 23 Jan 2013 Link to this post

    UPDATE: we found that placing our component NOT in a new window gets rid of the null reference, so it has something to do with the container that the AutoCompleteBox is placed on...

    The actual component is contained in a DataTemplate, and is added to the Content of the window just before it is shown

    UPDATE 2:
    It appears as though the null reference is thrown when the item source is changed, here is the full code for our extended autocompletebox that loads on focus. We have bound to searchtext, and keep searchtext updated by selected item with the event handler as well.

    class EmptyAutoCompleteBox : RadAutoCompleteBox {
            public EmptyAutoCompleteBox() {
                this.GotFocus += new RoutedEventHandler(EmptyAutoCompleteBox_GotFocus);
                this.SelectionChanged += new System.Windows.Controls.SelectionChangedEventHandler(EmptyAutoCompleteBox_SelectionChanged);
                this.FilteringBehavior = new SearchWhenEmptyBehaviour();
            }
     
            /* get around binding to search text not being updated when an item is selected from drop down */
            void EmptyAutoCompleteBox_SelectionChanged(object sender, System.Windows.Controls.SelectionChangedEventArgs e) {
                if (this.SelectedItem != null) {
                    this.SearchText = this.SelectedItem.ToString();
                }
            }
     
            /* open the dropdown when focused */
            void EmptyAutoCompleteBox_GotFocus(object sender, RoutedEventArgs e) {
                string searchText = this.SearchText;
                if (this.SelectedItem != null) {
                    searchText = BindingExpressionHelper.GetValue(this.SelectedItem, this.DisplayMemberPath).ToString();
                }
                this.IsDropDownOpen = false; //ohterwise it doesn't work the first time with mouse
                this.Populate(searchText);
            }
     
            /* catch the bugged null reference (needs a fix from telerik) */
            protected override void OnItemsSourceChanged(object newValue, object oldValue) {
                try {
                    base.OnItemsSourceChanged(newValue, oldValue);
                } catch (Exception) {
                    //do nothing
                }
            }
        }

    The stack trace from the caught exception:
    System.NullReferenceException was caught
      Message=Object reference not set to an instance of an object.
      Source=Telerik.Windows.Controls.Input
      StackTrace:
           at Telerik.Windows.Controls.RadAutoCompleteBox.OpenDropDown() in c:\TB\102\WPF_Scrum\Release_WPF\Sources\Development\Controls\Input\AutoCompleteBox\RadAutoCompleteBox.cs:line 1192
           at Telerik.Windows.Controls.RadAutoCompleteBox.OnIsDropDownOpenChanged(Boolean isOpen) in c:\TB\102\WPF_Scrum\Release_WPF\Sources\Development\Controls\Input\AutoCompleteBox\RadAutoCompleteBox.cs:line 672
           at Telerik.Windows.Controls.RadAutoCompleteBox.OnIsDropDownOpenChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) in c:\TB\102\WPF_Scrum\Release_WPF\Sources\Development\Controls\Input\AutoCompleteBox\RadAutoCompleteBox.cs:line 879
           at System.Windows.DependencyObject.OnPropertyChanged(DependencyPropertyChangedEventArgs e)
           at System.Windows.FrameworkElement.OnPropertyChanged(DependencyPropertyChangedEventArgs e)
           at System.Windows.DependencyObject.NotifyPropertyChange(DependencyPropertyChangedEventArgs args)
           at System.Windows.DependencyObject.UpdateEffectiveValue(EntryIndex entryIndex, DependencyProperty dp, PropertyMetadata metadata, EffectiveValueEntry oldEntry, EffectiveValueEntry& newEntry, Boolean coerceWithDeferredReference, Boolean coerceWithCurrentValue, OperationType operationType)
           at System.Windows.DependencyObject.SetValueCommon(DependencyProperty dp, Object value, PropertyMetadata metadata, Boolean coerceWithDeferredReference, Boolean coerceWithCurrentValue, OperationType operationType, Boolean isInternal)
           at System.Windows.DependencyObject.SetValue(DependencyProperty dp, Object value)
           at Telerik.Windows.Controls.RadAutoCompleteBox.set_IsDropDownOpen(Boolean value) in c:\TB\102\WPF_Scrum\Release_WPF\Sources\Development\Controls\Input\AutoCompleteBox\RadAutoCompleteBox.cs:line 362
           at Telerik.Windows.Controls.Primitives.AutoCompleteHelper.InvalidateIsDropDownOpen() in c:\TB\102\WPF_Scrum\Release_WPF\Sources\Development\Controls\Input\AutoCompleteBox\AutocompleteHelper.cs:line 219
           at Telerik.Windows.Controls.Primitives.AutoCompleteHelper.Populate(String text) in c:\TB\102\WPF_Scrum\Release_WPF\Sources\Development\Controls\Input\AutoCompleteBox\AutocompleteHelper.cs:line 97
           at Telerik.Windows.Controls.RadAutoCompleteBox.OnItemsSourceChanged(Object newValue, Object oldValue) in c:\TB\102\WPF_Scrum\Release_WPF\Sources\Development\Controls\Input\AutoCompleteBox\RadAutoCompleteBox.cs:line 659
           at tDLAS.component.EmptyAutoCompleteBox.OnItemsSourceChanged(Object newValue, Object oldValue) in C:\Users\cameron\Documents\GitHub\DLAS\tDLAS\component\EmptyAutoCompleteBox.cs:line 37
      InnerException:
  16. Ivo
    Admin
    Ivo avatar
    390 posts

    Posted 29 Jan 2013 Link to this post

    Hi Cameron,

    We tried to reproduce this into a sample project using the code you provided without any success. It would be great if you open  a new support ticket and send us a project reproducing this so we will be able to investigate it further.

    Regards,
    Ivo
    the Telerik team

    Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

  17. Greg
    Greg avatar
    7 posts
    Member since:
    Oct 2012

    Posted 08 Feb 2013 Link to this post

    The problem with the focus causing all records to display is that you can't then type into the box anymore. It basically transforms it into a drop down only. How can I get it so that the user can either type into the box, like normal, or can click into the box to see all records. That little snippet of GotFocus code disables the ability to type in the box.
  18. danparker276
    danparker276 avatar
    389 posts
    Member since:
    Aug 2010

    Posted 08 Feb 2013 Link to this post

    Greg, I can type and open a dropdown box at the same time. I'm using a button at the end though.  I'm not sure if it's the same thing, but it might be close.

    <StackPanel Orientation="Horizontal">
        <telerik:RadAutoCompleteBox  Name="myAutoCB"
                                     WatermarkContent="Enter ID or Search"
                                      ItemsSource="{Binding}"
                                     TextSearchPath="SearchStr"
                                     
                                     IsDropDownOpen="True"
                                     SelectionMode="Single"
                                  FilteringBehavior="{StaticResource EmptyTextFilteringBehavior}"
                                     LostFocus="myAutoCB_LostFocus_1"
                                 
                                 DropDownWidth="300"
                                     TextSearchMode="Contains"
                                   
                                     DropDownItemTemplate="{StaticResource MyT}"
                                     Width="285" Height="25"
                                     SelectionChanged="myAutoCB_SelectionChanged_1"
                                     />
        <telerik:RadButton Width="15" Name="tbOpenMyAutoCB" Content="v" Click="tbmyAutoCB_Click_1" />
    </StackPanel>
    private void tbmyAutoCB_Click_1(object sender, RoutedEventArgs e)
    {
        this.myAutoCB.IsDropDownOpen = false;
        this.myAutoCB.Focus();
        this.myAutoCB.Populate(this.racAttn.SearchText);
    }
  19. Greg
    Greg avatar
    7 posts
    Member since:
    Oct 2012

    Posted 08 Feb 2013 Link to this post

    Yeah, see I don't want a button. It should be able to do both. Hopefully a telerik person responds with an idea.
  20. Ivo
    Admin
    Ivo avatar
    390 posts

    Posted 14 Feb 2013 Link to this post

    Hello Greg,

    I tried to reproduce what you describe using one of the projects I previously attached into this thread - OpenOnFocusAutoComplete.zip without any success. You can find attached a video of what I tried. I tested it with both Q3 and Q3 SP1 and both the filtering and the open-on-focus functionalities worked properly. It would be great if you open a new support ticket and send us a sample project reproducing the issue you describe.

    Regards,
    Ivo
    the Telerik team

    Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

  21. Mack
    Mack avatar
    2 posts
    Member since:
    Mar 2013

    Posted 04 Apr 2013 Link to this post

    Martin,

    This worked very well fro me. Thanks.
  22. Vinod
    Vinod avatar
    7 posts
    Member since:
    Jul 2016

    Posted 04 Jul Link to this post

    Hi,

    I faced another issue like mouse left click is not working while selecting the item from the list.

    Enter and Right click is working fine for selecting item from the list.

    Kindly , let me know what is the solution for it..

  23. Nasko
    Admin
    Nasko avatar
    585 posts

    Posted 05 Jul Link to this post

    Hi Vinod,

    We noticed that you have asked a similar question in the following forum thread , but you were able to resolve it and posted your solution:
    http://www.telerik.com/forums/selecting-with-mouse-click-does-not-work

    Could you please confirm if now everything is working as expected for you?

    Regards,
    Nasko
    Telerik
    Do you need help with upgrading your AJAX, WPF or WinForms project? Check the Telerik API Analyzer and share your thoughts.
  24. Vinod
    Vinod avatar
    7 posts
    Member since:
    Jul 2016

    Posted 05 Jul in reply to Nasko Link to this post

    Thanks Nasko ..

     

    Its working for me...

Back to Top
UI for WPF is Visual Studio 2017 Ready