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

BeginEdit() unselect text in cells

1 Answer 308 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Owen
Top achievements
Rank 1
Owen asked on 05 Oct 2016, 10:31 PM

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

1 Answer, 1 is accepted

Sort by
0
Dess | Tech Support Engineer, Principal
Telerik team
answered on 10 Oct 2016, 07:14 AM
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.
Tags
GridView
Asked by
Owen
Top achievements
Rank 1
Answers by
Dess | Tech Support Engineer, Principal
Telerik team
Share this question
or