help: select all text on CommandBarDropDownList1

5 posts, 1 answers
  1. ricric
    ricric avatar
    12 posts
    Member since:
    Sep 2010

    Posted 08 Jul 2011 Link to this post

    how can i select all text when i click the text on CommandBarDropDownList1 ?

    thanks for your help..
  2. Ivan Todorov
    Admin
    Ivan Todorov avatar
    688 posts

    Posted 13 Jul 2011 Link to this post

    Hello Ricric,

    You can achieve this by subscribing to the events of the hosted text box. I am posting you an example that demonstrates this:
    public partial class CommandBarSample : Form
    {
        private bool isEntering;
     
        public CommandBarSample()
        {
            InitializeComponent();
     
            this.commandBarDropDownList1.DropDownListElement.TextBox.TextBoxItem.HostedControl.Enter += new EventHandler(CommandBarSample_Enter);
            this.commandBarDropDownList1.DropDownListElement.TextBox.TextBoxItem.HostedControl.MouseDown += new MouseEventHandler(HostedControl_MouseDown);
        }
     
        void HostedControl_MouseDown(object sender, MouseEventArgs e)
        {
            if (this.isEntering)
            {
                this.isEntering = false;
                (this.commandBarDropDownList1.DropDownListElement.TextBox.TextBoxItem.HostedControl as TextBox).SelectAll();
            }
        }
     
        void CommandBarSample_Enter(object sender, EventArgs e)
        {
            this.isEntering = true;
            (this.commandBarDropDownList1.DropDownListElement.TextBox.TextBoxItem.HostedControl as TextBox).SelectAll();
        }
     
    }

    I hope this is useful. Feel free to ask if you have any additional questions.

    Best wishes,
    Ivan Todorov
    the Telerik team

    Register for the Q2 2011 What's New Webinar Week. Mark your calendar for the week starting July 18th and book your seat for a walk through of all the exciting stuff we will ship with the new release!

  3. UI for WinForms is Visual Studio 2017 Ready
  4. ricric
    ricric avatar
    12 posts
    Member since:
    Sep 2010

    Posted 16 Jul 2011 Link to this post

    could you translate the code in vb.net please?
    thanks.
  5. Answer
    Ivan Todorov
    Admin
    Ivan Todorov avatar
    688 posts

    Posted 21 Jul 2011 Link to this post

    Hi Ricric,

    Here is the same code, translated into VB:
    Public Partial Class CommandBarSample
        Inherits Form
        Private isEntering As Boolean
     
        Public Sub New()
            InitializeComponent()
     
            AddHandler Me.commandBarDropDownList1.DropDownListElement.TextBox.TextBoxItem.HostedControl.Enter, AddressOf CommandBarSample_Enter
            AddHandler Me.commandBarDropDownList1.DropDownListElement.TextBox.TextBoxItem.HostedControl.MouseDown, AddressOf HostedControl_MouseDown
        End Sub
     
        Private Sub HostedControl_MouseDown(sender As Object, e As MouseEventArgs)
            If Me.isEntering Then
                Me.isEntering = False
                TryCast(Me.commandBarDropDownList1.DropDownListElement.TextBox.TextBoxItem.HostedControl, TextBox).SelectAll()
            End If
        End Sub
     
        Private Sub CommandBarSample_Enter(sender As Object, e As EventArgs)
            Me.isEntering = True
            TryCast(Me.commandBarDropDownList1.DropDownListElement.TextBox.TextBoxItem.HostedControl, TextBox).SelectAll()
        End Sub
     
    End Class

    In case you need to translate code snippets in the future, you can use our free Code Converter tool.

    Hope this helps.

    Kind regards,
    Ivan Todorov
    the Telerik team

    Register for the Q2 2011 What's New Webinar Week. Mark your calendar for the week starting July 18th and book your seat for a walk through of all the exciting stuff we will ship with the new release!

  6. ricric
    ricric avatar
    12 posts
    Member since:
    Sep 2010

    Posted 21 Jul 2011 Link to this post

    ok, thank you.
Back to Top
UI for WinForms is Visual Studio 2017 Ready