Open drop down values on Mouse Click after selecting item

9 posts, 1 answers
  1. Nirav
    Nirav avatar
    5 posts
    Member since:
    Oct 2014

    Posted 07 Oct 2014 Link to this post

    Hi,

    Existing behavior:
    I have a RadAutoCompleteBox with multiple selection in my WPF view.

    I have added the code to open the drop down values when mouse clicked for the first time or got focus on AutoCompeleteBox. After selecting the single item, I am not able to open the drop down values again by using mouse click. I have to focus on another element in the view and focus back to auto complete box, it opens the drop down values on mouse click.

    Problem:
    I want to open the drop down values on mouse click after selecting the item (not by typing).

    Reference:
    I have checked "Demo - Telerik UI for WPF", it also has the same behavior.

    Let me know if you have any questions.

    Kind Regards,
    NP.
  2. Kalin
    Admin
    Kalin avatar
    1207 posts

    Posted 08 Oct 2014 Link to this post

    Hi Nirav,

    What I can suggest you would be to hook to the MouseLeftButtonDown event of the control the following way:

    this.Auto.AddHandler(UIElement.MouseLeftButtonDownEvent, new MouseButtonEventHandler(OnMouseDown), true);

    And manually open the drop down in the handler - this way you will be able to open it on every mouse click inside of the control.

    Hope this helps.

    Regards,
    Kalin
    Telerik
     

    Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

     
  3. UI for WPF is Visual Studio 2017 Ready
  4. Nirav
    Nirav avatar
    5 posts
    Member since:
    Oct 2014

    Posted 08 Oct 2014 in reply to Kalin Link to this post

    Hi Kalin,

    Thanks for the reply.

    I have modified my code according to your suggestion. However, below are the issues I am having with the code changes:
    1. With mouse click, it open the drop down. But after I select any item, it opens again. So, selecting the item click also considered as MouseDown event. And it opens the drop down (which I don't want).
    2. For already selected items, to remove from selection - I have to click it twice on (X) button. On first click it opens the drop down, on second click it removes the item.

    Any work around to get this fixed?

    Thanks & Regards,
    NP


  5. Kalin
    Admin
    Kalin avatar
    1207 posts

    Posted 09 Oct 2014 Link to this post

    Hello Nirav,

    I'm sorry for misunderstanding - actually if you hook to the MouseLeftButtonUp and SelectionChanged you will be able to achieve the desired scenario. You would also need to raise a flag in order to prevent the opening when item is remove from the selection. So for example if you hook to the event and set the default value of the flag the following way:
    this.Auto.AddHandler(UIElement.MouseLeftButtonUpEvent, new MouseButtonEventHandler(OnMouseDown), true);
    this.shouldOpenDropDown = true;

    You will have to Implement the following MouseLeftButtonUp handler:

    private void OnMouseDown(object sender, MouseButtonEventArgs e)
    {
        if (!this.Auto.IsDropDownOpen && this.shouldOpenDropDown)
        {
            this.Auto.Populate("User");
            e.Handled = true;
        }
        else
        {
            this.shouldOpenDropDown = true;
        }
    }

    And the following SelectionChanged handler:

    private void Auto_SelectionChanged(object sender, SelectionChangedEventArgs e)
    {
        if (e.RemovedItems.Count > 0)
        {
            this.shouldOpenDropDown = false;
        }
    }

    Hope this will work for you.

    Regards,
    Kalin
    Telerik
     

    Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

     
  6. Nirav
    Nirav avatar
    5 posts
    Member since:
    Oct 2014

    Posted 10 Oct 2014 in reply to Kalin Link to this post

    Hi Kalin,

    Thanks for the code. It does work. BUT now I am having below issues:

    Scenario 1:
    1. Add more than one items in the auto complete box. Now click on (x) on any item. It opens the drop down (issue). Click on it again. Works perfectly fine fur current item and for next items in case of removal.
    2. After adding multiple items, remove all the items. Now mouse click on auto complete box, it does not open drop down(issue). Click again, works fine.

    Thanks & Regards,
    Nirav Patel.
  7. Kalin
    Admin
    Kalin avatar
    1207 posts

    Posted 10 Oct 2014 Link to this post

    Hi Nirav,

    I was not able to observe the explained issue in my sample project. However I will suggest you another simpler solution - to Populate to control only whenever the OriginalSource is RadWatermarkTextBox:

    private void OnMouseDown(object sender, MouseButtonEventArgs e)
    {
        if (!this.Auto.IsDropDownOpen && e.OriginalSource is RadWatermarkTextBox)
        {
            this.Auto.Populate("User");
        }
    }

    This way the drop down will only get opened whenever clicked in the WatermarkTextBox.

    Hope this will work for you.

    Regards,
    Kalin
    Telerik
     

    Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

     
  8. Nirav
    Nirav avatar
    5 posts
    Member since:
    Oct 2014

    Posted 12 Oct 2014 in reply to Kalin Link to this post

    Hi Kalin,

    Thanks for the reply.

    Above code does not work.
    I am using RadAutoCompleteBox, and I am getting e.OriginalSource value as System.Windows.Controls.TextBoxView.

    Let me know if you have any other questions regarding the implementation.

    Regards,
    NP.
  9. Answer
    Kalin
    Admin
    Kalin avatar
    1207 posts

    Posted 15 Oct 2014 Link to this post

    Hi Nirav,

    I'm sorry for misunderstanding - you should hook to the MouseLeftButtonUp instead of Down and there you will have the WatermarkTextBox as OriginalSource:

    this.Auto.AddHandler(UIElement.MouseLeftButtonUpEvent, new MouseButtonEventHandler(OnMouseLeftButtonUp), true);

    And use the following handler:

    private void OnMouseLeftButtonUp(object sender, MouseButtonEventArgs e)
    {
        if (!this.Auto.IsDropDownOpen && e.OriginalSource is RadWatermarkTextBox)
        {
            this.Auto.Populate("User");
        }
    }

    Hope this helps.

    Regards,
    Kalin
    Telerik
     

    Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

     
  10. Nirav
    Nirav avatar
    5 posts
    Member since:
    Oct 2014

    Posted 17 Oct 2014 in reply to Kalin Link to this post

    Hi Kalin,

    Thanks for the code. That's exactly what I needed. It did work for me.

    Regards,
    NP
Back to Top
UI for WPF is Visual Studio 2017 Ready