Issue in editable grid cell - when selecting the value

1 Answer 92 Views
GridView
Giri
Top achievements
Rank 1
Iron
Giri asked on 25 Oct 2022, 04:53 PM

Hello Team,

In cell biginedit, the text is selected and focused at the end of the value. If I click the cell, the text shows the front text. clicking on the tab key. The cell value again shows the last value. It should show the first value.

Using this code to bind the grid cell - Microsoft.VisualBasic.Val(7)/1000 & Left (CD & Space (20), 20)

Here, the cell value shows "7", but we need to show a "CD" on the front. Please help us resolve this issue. A video link has been added for your convenience.

Video link : https://suganya-gmail.tinytake.com/df/1379872/thumbnail?type=attachments&version_no=0&file_version_no=0&thumbnail_size=preview

Screenshot : https://prnt.sc/_ZlhOr-sovVe

1 Answer, 1 is accepted

Sort by
0
Dess | Tech Support Engineer, Principal
Telerik team
answered on 26 Oct 2022, 11:27 AM
Hello, Giri,     

By default, when a text cell enters edit mode its text is selected which means that the selection starts at index 0 and its length corresponds to the symbols count in the cell's text. That is why the cursor is placed after the last symbol. Note that if you want to apply any settings to the editor, the appropriate place to do it is the CellEditorInitialized event which is fired after the editor has been initialized by RadGridView. 
        private void radGridView1_CellEditorInitialized(object sender, GridViewCellEventArgs e)
        {
            RadTextBoxEditor tbEditor = e.ActiveEditor as RadTextBoxEditor;
            if (tbEditor != null)
            {
                RadTextBoxEditorElement element = tbEditor.EditorElement as RadTextBoxEditorElement;
                element.Text = "CD" + e.Row.Cells[e.Column.Name].Value;
               
                element.TextBoxItem.GotFocus -= TextBoxItem_GotFocus;
                element.TextBoxItem.GotFocus += TextBoxItem_GotFocus;
            }
        }

        private void TextBoxItem_GotFocus(object sender, EventArgs e)
        {
            RadTextBoxItem tb = sender as RadTextBoxItem;
            tb.SelectionStart = tb.Text.Length;
        }

I believe that it would be helpful for achieving your custom requirement.

Regards,
Dess | Tech Support Engineer, Principal
Progress Telerik

Love the Telerik and Kendo UI products and believe more people should try them? Invite a fellow developer to become a Progress customer and each of you can get a $50 Amazon gift voucher.

Tags
GridView
Asked by
Giri
Top achievements
Rank 1
Iron
Answers by
Dess | Tech Support Engineer, Principal
Telerik team
Share this question
or