Articles in this section
Category / Section

How to select entire text on mouse click in WPF MultiColumnDropDown (SfMultiColumnDropDown)?

2 mins read

WPF MultiColumnDropDown (SfMultiColumnDropDown) allows you to edit via TextBox. You can select the text displayed in the textbox when it got the focus from any other control by wiring the Loaded event of WPF MultiColumnDropDown (SfMultiColumnDropDown) and calling the TextBox Control SelectAll method in the TextBox.PreviewMouseLeftButtonUp event and defining the Boolean property customization in lost focus event.

public partial class MainWindow : Window
{
        public MainWindow()
        {
            InitializeComponent();
            this.MultiColumnControl.Loaded += MultiColumnControl_Loaded;
        }
 
        void MultiColumnControl_Loaded(object sender, RoutedEventArgs e)
        {
            TextBox textBox = (TextBox)GridUtil.FindDescendantChildByType(MultiColumnControl, typeof(TextBox));
            textBox.PreviewMouseLeftButtonUp += TextBox_PreviewMouseLeftButtonUp;
            textBox.LostFocus += TextBox_LostFocus;
        }
 
        private void TextBox_LostFocus(object sender, RoutedEventArgs e)
        {
            //Enable the boolean property after lost focus of SfMultiColumnDropDownControl 
            mouseClickSelection = true;
        }
 
        //declare the bollean property 
        bool mouseClickSelection = true;
 
        private async void TextBox_PreviewMouseLeftButtonUp(object sender, System.Windows.Input.MouseButtonEventArgs e)
        {
            TextBox tb = sender as TextBox;
            //Check the condition when selection apply or not 
            if (mouseClickSelection)
            {
                await Application.Current.Dispatcher.InvokeAsync(tb.SelectAll);
                //disable the boolean porperty to selection apply only first time in SfMultiColumnDropDownControl via mouse click 
                mouseClickSelection = false;
            }
        }
 
        protected override void OnClosing(CancelEventArgs e)
        {
            TextBox textBox = (TextBox)GridUtil.FindDescendantChildByType(MultiColumnControl, typeof(TextBox));
            textBox.PreviewMouseLeftButtonUp -= TextBox_PreviewMouseLeftButtonUp;
            this.MultiColumnControl.Loaded -= MultiColumnControl_Loaded;
        }
}

Select entire text while editor got focus in SfMultiColumnDropDownControl

The following screenshot shows the selecting text when editor got focus in WPF MultiColumnDropDown (SfMultiColumnDropDown),

Shows the selected text while editor got focus in SfMultiColumnDropDownControl

Take a moment to peruse the WPF MultiColumnDropDown - Editing and Auto complete documentation, where you can find about editing and auto complete with code examples.

Please refer this link to know about the essential features of WPF MultiColumnDropDown.

You can download the example from GitHub

 

Did you find this information helpful?
Yes
No
Help us improve this page
Please provide feedback or comments
Comments (0)
Please  to leave a comment
Access denied
Access denied