BeginEdit() unselect text in cells

2 posts, 0 answers
  1. Owen
    Owen avatar
    1 posts
    Member since:
    Sep 2016

    Posted 05 Oct Link to this post

    Hi,

    I meet a question on BeginEdit() function. When I call "this.gridView.Rows[1].Cells[1].BeginEdit();" , the text in Rows[1].Cells[1] will be selected so user will overwrite the previous text with the new type. I notice  System.Windows.Forms has a function  "BeginEdit(bool)" in GridView so developer can call

    "BeginEdit(bool)" to not select any contents. Does Telerik has any similar functions to help me unselect text in a Cell? Or How can I unselect text in a Cell programmaticly if I call BeginEdit()?

     

    Thank you,

    Chen

  2. Dess
    Admin
    Dess avatar
    1607 posts

    Posted 10 Oct Link to this post

    Hello Chen,

    Thank you for writing.  

    In order to clear the selection of RadTextBoxEditor, it is necessary to handle the RadGridView.CellEditorInitialized event and subscribe to the GotFocus event of the hosted text box in the editor. Then, clear the selection as it is demonstrated below:
    public RadForm1()
    {
        InitializeComponent();
        this.radGridView1.CellEditorInitialized += radGridView1_CellEditorInitialized;
    }
     
    private void radGridView1_CellEditorInitialized(object sender, Telerik.WinControls.UI.GridViewCellEventArgs e)
    {
        RadTextBoxEditor tbEditor = e.ActiveEditor as RadTextBoxEditor;
        if (tbEditor != null)
        {
            RadTextBoxEditorElement el = tbEditor.EditorElement as RadTextBoxEditorElement;
            el.TextBoxItem.TextBoxControl.GotFocus -= TextBoxControl_GotFocus;
            el.TextBoxItem.TextBoxControl.GotFocus += TextBoxControl_GotFocus;
        }
    }
     
    private void TextBoxControl_GotFocus(object sender, EventArgs e)
    {
        TextBox tb = sender as TextBox;
        tb.SelectionLength = 0;
        tb.SelectionStart = tb.Text.Length;
    }

    I hope this information helps. Should you have further questions I would be glad to help.

    Regards,
    Dess
    Telerik by Progress
    Check out the Windows Forms project converter, which aids the conversion process from standard Windows Forms applications written in C# or VB to Telerik UI for WinForms.For more information check out this blog post and share your thoughts.
  3. UI for WinForms is Visual Studio 2017 Ready
Back to Top