This is a migrated thread and some comments may be shown as answers.

BrowseEditor - select all text/clean all

2 Answers 30 Views
BrowseEditor
This is a migrated thread and some comments may be shown as answers.
Artem
Top achievements
Rank 1
Artem asked on 28 Oct 2013, 08:19 AM
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 Answers, 1 is accepted

Sort by
0
Accepted
George
Telerik team
answered on 30 Oct 2013, 06:08 PM
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 >>
0
Artem
Top achievements
Rank 1
answered on 31 Oct 2013, 06:43 AM
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!
Tags
BrowseEditor
Asked by
Artem
Top achievements
Rank 1
Answers by
George
Telerik team
Artem
Top achievements
Rank 1
Share this question
or