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

Gridview Cell Edit Click

1 Answer 85 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Jeff
Top achievements
Rank 1
Jeff asked on 18 Jun 2014, 03:01 PM
I'm able to edit cells correctly, however, if there is a cell with a particular long sentence, it will go to the end of the sentence when I click into the cell to edit.
Example, a cell containing a sentence
"I watched XXXXX TV show this weekend" - I click in there and I can click directly into the XXXXX as the sentence isn't too long.
"I first went to the store then came home and watched XXXXX TV show" - I click in there and it will highlight the sentence but take me to the last part of the sentence that fills up the cell.

Is there a way to adjust where you can click into the cell or an easier way to edit in the situation where a sentence is much longer?

Thanks,
Jeff

1 Answer, 1 is accepted

Sort by
0
Dess | Tech Support Engineer, Principal
Telerik team
answered on 23 Jun 2014, 08:25 AM
Hello Jeff,

Thank you for writing.

You can manipulate the selection in the RadTextBoxEditor using the CellEditorInitialized event to subscribe to the TextBoxItem.GotFocus event and manipulate its start. Here is a sample approach:
public Form1()
{
    InitializeComponent();
 
    for (int i = 0; i < 10; i++)
    {
        this.radGridView1.Rows.Add(i, "I first went to the store then " +
                                      "came home and watched XXXXX TV show", DateTime.Now.AddDays(i));
    }
}
 
private void radGridView1_CellEditorInitialized(object sender, GridViewCellEventArgs e)
{
    RadTextBoxEditor tb = e.ActiveEditor as RadTextBoxEditor;
    if (tb != null)
    {
        RadTextBoxEditorElement element = tb.EditorElement as RadTextBoxEditorElement;
        element.TextBoxItem.GotFocus -= TextBoxItem_GotFocus;
        element.TextBoxItem.GotFocus += TextBoxItem_GotFocus;
    }
}
 
private void TextBoxItem_GotFocus(object sender, EventArgs e)
{
    RadTextBoxItem tbItem = sender as RadTextBoxItem;
    tbItem.Select(0, 0);
    Point localPoint = tbItem.HostedControl.PointToClient(Control.MousePosition);
    int selectedCharIndex = ((TextBox)tbItem.HostedControl).GetCharIndexFromPosition(localPoint);
    tbItem.SelectionStart = selectedCharIndex;
    tbItem.SelectionLength = 1;
}

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

Regards,
Desislava
Telerik
 
Check out Telerik Analytics, the service which allows developers to discover app usage patterns, analyze user data, log exceptions, solve problems and profile application performance at run time. Watch the videos and start improving your app based on facts, not hunches.
 
Tags
GridView
Asked by
Jeff
Top achievements
Rank 1
Answers by
Dess | Tech Support Engineer, Principal
Telerik team
Share this question
or