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

Should GridView exit edit mode when user clicks on read only cell?

3 Answers 484 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Lukasz
Top achievements
Rank 1
Lukasz asked on 12 Sep 2017, 10:12 AM

Hi,

I am using Q3 2015.

I have editable RadGridView with two rows: Name and Count.

Name is editable.

Count is readonly.

When user clicks on "new row indicator" new row is created and focus is set to Name cell.

User enters text in name cell and clicks on "Count" cell.

My problem is that row remains in edit mode, "new row indicator" is not visible. User is confused because he thinks that edit is finished and there is no way to add another row.

To finish row edit user have to use tab key or click on any other control. Is there a way to end edit mode when any of readonly cells are focused?

My grid configuration:

<telerik:RadGridView
    x:Name="DocumentPositionsGridView"
    Style="{StaticResource EditableGridViewStyle}"
    SelectionMode="Extended"
    ItemsSource="{Binding Data, ValidatesOnDataErrors=True, NotifyOnValidationError=True}"
    ValidatesOnDataErrors="InViewMode"
    AddingNewDataItem="DocumentPositionsGridView_AddingNewDataItem"
    CellEditEnded="DocumentPositionsGridView_CellEditEnded"
    CanUserDeleteRows="{Binding CanEditDocumentPositions}"
    CanUserInsertRows="{Binding CanEditDocumentPositions}"
    NewRowPosition="{Binding CanEditDocumentPositions, Converter={StaticResource BooleanToGridViewNewRowPositionConverter}}"
    ShowColumnFooters="True"
    >
 
<Style x:Key="EditableGridViewStyle" TargetType="{x:Type telerik:RadGridView}" BasedOn="{StaticResource RadGridViewStyle}">
    <Setter Property="ShowGroupPanel" Value="False"/>
    <Setter Property="AutoGenerateColumns" Value="False"/>
    <Setter Property="IsFilteringAllowed" Value="False"/>
    <Setter Property="GroupRenderMode" Value="Flat"/>
    <Setter Property="NewRowPosition" Value="Bottom"/>
</Style>



 

 

3 Answers, 1 is accepted

Sort by
0
Dinko | Tech Support Engineer
Telerik team
answered on 15 Sep 2017, 10:25 AM
Hi Lukasz,

Thank you for your interest in RadGridView control.

I need more time to check your scenario. I will contact as soon as I have more information about your case.

Regards,
Dinko
Progress Telerik
Want to extend the target reach of your WPF applications, leveraging iOS, Android, and UWP? Try UI for Xamarin, a suite of polished and feature-rich components for the Xamarin framework, which allow you to write beautiful native mobile apps using a single shared C# codebase.
0
Accepted
Dinko | Tech Support Engineer
Telerik team
answered on 19 Sep 2017, 04:56 PM
Lukasz,

Thank you for your patience.

This is expected behavior because the editing process of the row is still not ended when you select a cell of the same row. An approach which I can suggest you is to subscribe to the CurrentCellChanged event of the RadGridView. In the event handler, you can check if a row is in edit mode and the current clicked cell is in a column with an IsReadOnly property set to True.
private void DocumentPositionsGridView_CurrentCellChanged(object sender, Telerik.Windows.Controls.GridViewCurrentCellChangedEventArgs e)
{
    var grid = sender as RadGridView;
    if(grid.RowInEditMode != null && e.NewCell.Column.IsReadOnly)
    {               
        grid.CommitEdit();
    }            
}
Finally, you can call the CommitEdit() method to end the editing process.

Regards,
Dinko
Progress Telerik
Want to extend the target reach of your WPF applications, leveraging iOS, Android, and UWP? Try UI for Xamarin, a suite of polished and feature-rich components for the Xamarin framework, which allow you to write beautiful native mobile apps using a single shared C# codebase.
0
Lukasz
Top achievements
Rank 1
answered on 20 Sep 2017, 10:19 AM

I finally created custom class derived from RadGridView (below). This way I can just simply change my RadGridView to myns:EditableGridView. I had to create code-only control to be able to use x:Name inside grid row column definitions.

Many thanks for giving me directions.

/**
 * */
public class EditableRadGridView : RadGridView
{
    public EditableRadGridView()
    {
        CurrentCellChanged += EditableRadGridView_CurrentCellChanged;
    }
 
    /**
     * Finish edit when user clicks read only cell
     * */
    private void EditableRadGridView_CurrentCellChanged(object sender, GridViewCurrentCellChangedEventArgs e)
    {
        if (RowInEditMode != null && e.NewCell.Column.IsReadOnly)
            CommitEdit();
    }
}
Tags
GridView
Asked by
Lukasz
Top achievements
Rank 1
Answers by
Dinko | Tech Support Engineer
Telerik team
Lukasz
Top achievements
Rank 1
Share this question
or