cell edit

2 posts, 0 answers
  1. AJing
    AJing avatar
    19 posts
    Member since:
    Jun 2011

    Posted 07 Nov 2011 Link to this post

          1. How to put cell into edit mode and editing cursor to the cell contents after the last character when double-click ?
          2. How to put cell into focus state when cell end-edit?

      We now solve the tow problems as follows:
         1. Using cell double-click event & SenderKeys{"End"} 
         2. Using CellEndEdit event 

    The result is:
            Occasionally , the cell which in the edit mode contents are all selected what  is 
    not expected.

    Looking forword to you!
  2. Stefan
    Stefan avatar
    2908 posts

    Posted 10 Nov 2011 Link to this post

    Hello Ajing,

    Thank you for writing.

    The first time when you double click a cell, if the cell is CurrentCell, the editor will get opened on the first click and the cursor will be placed where you have clicked on the second click. Alternatively, if you click a cell that is not CurrentCell, the first click will make it current and the second will open its editor. So, what we can do is to subscribe to the CellEditorInitialized event and there subscribe to the GotFocus event of text box editor of the desired column. In the GotFocus event handler, you can set the desired position of the caret. However, this will only cover the second case, where you are double clicking a cell which is not current. Handling the first scenario is hard to determine task, since we do not have the exact case, when to move the caret position.
    void radGridView1_CellEditorInitialized(object sender, GridViewCellEventArgs e)
        if (e.Column.Name == "Name")
            RadTextBoxEditor editor = e.ActiveEditor as RadTextBoxEditor;
            RadTextBoxEditorElement element = editor.EditorElement as RadTextBoxEditorElement;
            element.TextBoxItem.GotFocus -= new EventHandler(TextBoxItem_GotFocus);
            element.TextBoxItem.GotFocus += new EventHandler(TextBoxItem_GotFocus);
            element.TextBoxItem.DoubleClick += new EventHandler(TextBoxItem_DoubleClick);
    void TextBoxItem_GotFocus(object sender, EventArgs e)
        RadTextBoxItem item = sender as RadTextBoxItem;
        item.SelectionLength = 0;
        item.SelectionStart = item.Text.Length;

    Alternatively, the SendKeys approach should work correctly in all cases. And if it is better for you, you can stick with it.

    In regards to your second question, you can make a cell current by setting the CurrentRow and CurrentColumn properties of RadGridView:
    void radGridView1_CellEndEdit(object sender, GridViewCellEventArgs e)
        radGridView1.CurrentRow = radGridView1.Rows[5];
        radGridView1.CurrentColumn = radGridView1.Columns[2];

    I hope that you find this information helpful. Should you have any other questions, do not hesitate to contact us.
    Kind regards,
    the Telerik team

    Q2’11 SP1 of RadControls for WinForms is available for download (see what's new); also available is the Q3'11 Roadmap for Telerik Windows Forms controls.

Back to Top