BrowseEditor - select all text/clean all

3 posts, 1 answers
  1. Artem
    Artem avatar
    16 posts
    Member since:
    May 2013

    Posted 28 Oct 2013 Link to this post

    Hi gyus
    I am using BrowseEditor in my application. There are 3 different scenarios how the user can do the same task of selecting a file for processing:
    1) browse to file using dialog that pops up from browse editor
    2) enter the path by Ctr+V the path to browse editor
    3) drag and drop the file  to browse editor

    1 and 3 are implemented, no problems with them. But I do have a small problem with 2.
    The default behavior I am regular to is that all text is selected when I do Ctrl+A, or if I click the field and it gains focus the whole text is selected. Otherwise I have to manually erase all text by pressing Backspace many times before I can paste new file path.

    And I did something wrong, or browseeditor does not implement Ctrl + A behavior.
    I succeed to do it by :
    private void radBrowseEditor1_KeyUp(object sender, KeyEventArgs e)
    {
        if (e.Control && e.KeyValue.Equals('A'))
            if (radBrowseEditor1 != null)
                if (radBrowseEditor1.BrowseElement != null)
                    if (radBrowseEditor1.BrowseElement.TextBoxItem != null)
                        radBrowseEditor1.BrowseElement.TextBoxItem.SelectAll();
    }

    Is it a correct approach?
    And how can I implement the behavior when gaining a focus leads to selecting all?

    Regards,
    Artem
  2. Answer
    George
    Admin
    George avatar
    500 posts

    Posted 30 Oct 2013 Link to this post

    Hi Artem,

    Thank you for contacting us.

    You can use the GotFocus method of the TextBoxItem:
    void TextBoxItem_GotFocus(object sender, EventArgs e)
    {
        this.radBrowseEditor1.BrowseElement.TextBoxItem.HostedControl.BeginInvoke(new Action(() =>
        {
            this.radBrowseEditor1.BrowseElement.TextBoxItem.TextBoxControl.SelectionStart = 0;
            this.radBrowseEditor1.BrowseElement.TextBoxItem.TextBoxControl.SelectionLength =
                this.radBrowseEditor1.BrowseElement.TextBoxItem.TextBoxControl.Text.Length;
        }));
    }

    We need to use BeginInvoke because otherwise the selection is lost since the MouseDown event is fired after the focus event.

    I hope this helps.

    Regards,
    George
    Telerik
    TRY TELERIK'S NEWEST PRODUCT - EQATEC APPLICATION ANALYTICS for WINFORMS.
    Learn what features your users use (or don't use) in your application. Know your audience. Target it better. Develop wisely.
    Sign up for Free application insights >>
  3. UI for WinForms is Visual Studio 2017 Ready
  4. Artem
    Artem avatar
    16 posts
    Member since:
    May 2013

    Posted 31 Oct 2013 Link to this post

    George, many thanks!
    Now my editor knows to select all text both on Ctrl + A pressed and focus gained event.
    It also supports drag and drop. That is already a usable control :)
    I am happy, thanks!
Back to Top