We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date

Enter cell edit mode in code behind

I have customized a GridTreeColumn by setting the StyleInfo.CellItemTemplate to a custom DataTemplate. But when I hit TAB the cell does not enter cell edit mode. I can see it has focus but I am unable to enter a value unless I double-click first. How can I force the cell to enter edit mode in code behind?

1 Reply

RA Riyaj Ahamed I Syncfusion Team June 19, 2012 07:14 AM UTC

Hi Oscar,

 

Thanks for your interest in Syncfusion products.

 

Yes, you can force Data Template cell to enter edit mode while pressing tab key. You can achieve your requirement by using CurrentCellActivated event as follows,

 

Code Snippet[C#]:

 

void InternalGrid_CurrentCellActivated(object sender, Syncfusion.Windows.ComponentModel.SyncfusionRoutedEventArgs args)

        {

            GridControl control = sender as GridControl;

            if (control != null)

            {

                if (control.CurrentCell.Renderer != null)

                {

                    UIElement element = control.CurrentCell.Renderer.CurrentCellUIElement;

                    if (element != null)

                    {

                        TextBox text_box = DependencyObjectExtensions.FindElementOfType<TextBox>(element as FrameworkElement);

                        if (text_box != null)

                        {

                            text_box.Focus();

                            //if it's a TextBox, move caret to the end.

                            if (text_box != null)

                            {

                                text_box.SelectionStart = text_box.Text.Length;

                            }

                        }

                    }

                }

            }

        }

 

 

We have prepared a sample based on this and you can find the sample under the following location,

 

Sample: SampleFor103961.zip

 

Note: In DataTemplate cell you can place any control. But the Grid doesn’t know what kind of control present inside the DataTemplate cell. Hence, when you press the Tab key, the data template cell is not entered to the edit mode. By using the CurrentCellActivated event you can directly force the control placed in cell template to enter edit mode.

 

Please let us know if you have any queries.

 

Regards,

Riyaj Ahamed I



SampleFor103961_b60bb1bd.zip

Loader.
Live Chat Icon For mobile
Up arrow icon