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
close icon

How to automatically set grid cells to edit mode

Hi, I am struggling to get the SfDataGrid to automatically change to edit mode when you change cells.  Pressing F2 to start editing took me ages to figure out!

                <sf:SfDataGrid VerticalAlignment="Stretch" HorizontalAlignment="Stretch" Name="FieldsGrid" AutoGenerateColumns="False" ItemsSource="{Binding Path=Fields}" AllowEditing="True"
                               AllowSorting="False" AllowFiltering="False" EditTrigger="OnTap" CurrentCellActivating="FieldsGrid_OnCurrentCellActivating">
                    <syncfusion:SfDataGrid.Columns>
                        <syncfusion:GridTextColumn HeaderText="Field ID" MappingName="ID" AllowEditing="False" />
                        <syncfusion:GridTextColumn HeaderText="Field Name" MappingName="Name" />
                        <syncfusion:GridComboBoxColumn HeaderText="Data Type" MappingName="DataType" ItemsSource="{Binding Path=AvailableDataTypes}" />
                        <syncfusion:GridTextColumn HeaderText="Data Size" MappingName="DataSize" />
                    </syncfusion:SfDataGrid.Columns>
                </sf:SfDataGrid>

        private void FieldsGrid_OnCurrentCellActivating(object sender, CurrentCellActivatingEventArgs args)
        {           
            FieldsGrid.SelectionController.CurrentCellManager.BeginEdit();           
        }

The OnCurrentCellActivating event fires when I change cell, but the BeginEdit call is not putting the grid into edit mode.  I have to either click using the mouse or press F2 to edit.  What am I missing please?

3 Replies

JG Jai Ganesh S Syncfusion Team May 18, 2016 09:23 AM UTC

Hi Craig, 
 
You can go to edit mode when you click the cell by setting the EditTrigger as  OnTap like below, 
 
<Syncfusion:SfDataGrid x:Name="datagrid" 
                               AllowEditing="True" 
                               AllowFiltering="True" 
                               AllowSorting="True"  
                               EditTrigger="OnTap" 
                               AutoGenerateColumns="False" 
                               ItemsSource="{Binding ItemsCollection}" 
                               ShowGroupDropArea="True" 
                               ShowRowHeader="True"/> 
 
 
or if you want to edit the cell while key navigation  by call the BeginEdit() in CurrentcellActivated event like below, 
 
this.datagrid.CurrentCellActivated += datagrid_CurrentCellActivated; 
 
void datagrid_CurrentCellActivated(object sender, CurrentCellActivatedEventArgs args) 
 { 
    if(!datagrid.SelectionController.CurrentCellManager.CurrentCell.IsEditing && args.ActivationTrigger==ActivationTrigger.Keyboard) 
       datagrid.SelectionController.CurrentCellManager.BeginEdit();       
 } 
 
Regards, 
Jai Ganesh S 



CG Craig Greenway May 18, 2016 10:06 AM UTC

Thanks I chose the wrong event (activating rather than activated)


JG Jai Ganesh S Syncfusion Team May 19, 2016 09:35 AM UTC

Hi Craig, 
 
Thank you for the update. 
 
Please let us know if you need further assistance on this. 
 
Regards, 
Jai Ganesh S 


Loader.
Live Chat Icon For mobile
Up arrow icon