Radautocompletebox dropdown stay open on multiselecting

1 Answer 43 Views
AutoCompleteBox ComboBox
Kai
Top achievements
Rank 1
Kai asked on 07 Jul 2021, 11:38 AM

Hello,

I am using a RadAutoCompleteBox with multiselecting. 

I would like a user to be able to open the dropdown by clicking on the AutoCompleteBox and to be able to select all needed items in one go.

In general it should have the same behaviour like the StaysOpenOnEdit property of the RadComboBox.

Thanks in advance

 

Regards,

Kai

Kai
Top achievements
Rank 1
commented on 10 Jul 2021, 10:32 PM

Any update on that ?

1 Answer, 1 is accepted

Sort by
0
Accepted
Martin Ivanov
Telerik team
answered on 12 Jul 2021, 11:18 AM

Hello Kai,

The required functionality is not supported by RadAutoCompleteBox. To achieve your requirement you can use some custom code. For example, you can handle the click event in the dropdown part of the control and manually select the items. Here is one way to do this:

public class CustomAutoCompleteBox : RadAutoCompleteBox
{
	private RadListBox itemsControlPart;

	public override void OnApplyTemplate()
	{
		base.OnApplyTemplate();

		itemsControlPart = (RadListBox)GetTemplateChild("PART_ListBox");
		itemsControlPart.AddHandler(RadListBox.PreviewMouseLeftButtonDownEvent, new RoutedEventHandler(OnListBoxPreviewMouseLeftButtonDown), true);

	}

	private void OnListBoxPreviewMouseLeftButtonDown(object sender, RoutedEventArgs e)
	{
		e.Handled = true;

		var containerUnderMouse = ((FrameworkElement)e.OriginalSource).ParentOfType<RadListBoxItem>();
		if (containerUnderMouse != null)
		{
			if (this.SelectionMode == Telerik.Windows.Controls.Primitives.AutoCompleteSelectionMode.Single)
			{
				itemsControlPart.SelectedItem = containerUnderMouse.DataContext;
				SelectedItem = containerUnderMouse.DataContext;
			}
			else
			{
				if (itemsControlPart.SelectedItems.Contains(containerUnderMouse.DataContext))
				{
					itemsControlPart.SelectedItems.Remove(containerUnderMouse.DataContext);
					((IList)SelectedItems).Remove(containerUnderMouse.DataContext);
				}
				else
				{
					itemsControlPart.SelectedItems.Add(containerUnderMouse.DataContext);
					((IList)SelectedItems).Add(containerUnderMouse.DataContext);
				}
			}
			
		}

		var textBoxPart = this.FindChildByType<RadWatermarkTextBox>();
		textBoxPart.Focus();
	}
}

I hope that helps.

Regards,
Martin Ivanov
Progress Telerik

Love the Telerik and Kendo UI products and believe more people should try them? Invite a fellow developer to become a Progress customer and each of you can get a $50 Amazon gift voucher.

Kai
Top achievements
Rank 1
commented on 12 Jul 2021, 11:52 AM

Could you provide me with a sample project with this functionality?
Martin Ivanov
Telerik team
commented on 15 Jul 2021, 10:54 AM

I've attached a small example showing this.

You can also take a look at the RadMultiColumnComboBox control which supports this functionality.

Tags
AutoCompleteBox ComboBox
Asked by
Kai
Top achievements
Rank 1
Answers by
Martin Ivanov
Telerik team
Share this question
or