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

Open drop down values on Mouse Click after selecting item

8 Answers 742 Views
AutoCompleteBox
This is a migrated thread and some comments may be shown as answers.
Nirav
Top achievements
Rank 1
Nirav asked on 08 Oct 2014, 01:58 AM
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.

8 Answers, 1 is accepted

Sort by
0
Kalin
Telerik team
answered on 08 Oct 2014, 12:28 PM
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.

 
0
Nirav
Top achievements
Rank 1
answered on 08 Oct 2014, 10:54 PM
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


0
Kalin
Telerik team
answered on 09 Oct 2014, 01:20 PM
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.

 
0
Nirav
Top achievements
Rank 1
answered on 10 Oct 2014, 05:45 AM
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.
0
Kalin
Telerik team
answered on 10 Oct 2014, 09:42 AM
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.

 
0
Nirav
Top achievements
Rank 1
answered on 13 Oct 2014, 12:23 AM
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.
0
Accepted
Kalin
Telerik team
answered on 15 Oct 2014, 08:43 AM
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.

 
0
Nirav
Top achievements
Rank 1
answered on 17 Oct 2014, 06:29 AM
Hi Kalin,

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

Regards,
NP
Tags
AutoCompleteBox
Asked by
Nirav
Top achievements
Rank 1
Answers by
Kalin
Telerik team
Nirav
Top achievements
Rank 1
Share this question
or