SingleMode with border and close button

4 posts, 0 answers
  1. Philippe
    Philippe avatar
    2 posts
    Member since:
    Apr 2019

    Posted 27 Jul Link to this post

    Hello,

    On an AutoCompleteBox, :

    - MultipleMode : The selection have a border and a close button. It's really easy to remove the selection. But the number of selection is not limited.

    - SingleMode : The selection have no border and close button.

    Is it possible to have SingleMode with the border and the close button ? Or is it possible to limit the selection quantity of MultipleMode to 1 ?

    Best regards

    Philippe

  2. Vladimir Stoyanov
    Admin
    Vladimir Stoyanov avatar
    495 posts

    Posted 31 Jul Link to this post

    Hello Philippe,

    Please, check the following example from our SDK repository that demonstrates how to add a button that clears the current SelectedItem when the SelectionMode is Single - the same behavior as the button visualized inside the boxes of the selected items with Multiple selection:
    https://github.com/telerik/xaml-sdk/tree/master/AutoCompleteBox/SingleSelectionModeWithClearButton

    Please, let us know if that is the desired functionality or visualizing the item inside a box is also required.

    Regards,
    Vladimir Stoyanov
    Progress Telerik
    Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
  3. Philippe
    Philippe avatar
    2 posts
    Member since:
    Apr 2019

    Posted 31 Jul in reply to Vladimir Stoyanov Link to this post

    Hello Vladimir,

    Thank you for your answer.
    I'm really disapointed. AutoCompleteBox in MultipleMode is beautiful and easy to code.
    In this example, i need to manage all manually and the cross is on the right.

    Is it possible, in MultipleMode to limit the quantity of selected item to 1 ?

    Best regards

    Philippe

  4. Vladimir Stoyanov
    Admin
    Vladimir Stoyanov avatar
    495 posts

    Posted 05 Aug Link to this post

    Hello Philippe,

    I am afraid that by design in single selection, the selected item is displayed in the RadWaterMarkTextBox element. That said, I can suggest leaving the SelectionMode to Mulitple and handling the SelectionChanged event in a similar manner:
    private void AutoCompleteBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
            {
                var autoCompleteBox = sender as RadAutoCompleteBox;
                var count = 0;
                foreach (var item in autoCompleteBox.SelectedItems)
                {
                    count++;
                }
     
                if (count == 1)
                {
                    var watermarkTextBox = autoCompleteBox.ChildrenOfType<RadWatermarkTextBox>().FirstOrDefault();
                    watermarkTextBox.Visibility = Visibility.Collapsed;
                }
                else if(count == 0)
                {
                    var watermarkTextBox = autoCompleteBox.ChildrenOfType<RadWatermarkTextBox>().FirstOrDefault();
                    watermarkTextBox.Visibility = Visibility.Visible;
                }
            }

    This way, if there is a SelectedItem, the RadWatermarkTextBox will be collapsed and it will be shown only when the item is unselected. 

    Please, give this approach a try and let me know how it goes.

    Regards,
    Vladimir Stoyanov
    Progress Telerik
    Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
Back to Top