Set focus to first cell of selected item when RadGridView initially shown

1 Answer 84 Views
GridView
Stephen
Top achievements
Rank 1
Stephen asked on 21 Nov 2024, 02:40 PM

What is necessary to get a RadGridView to focus the first cell of the row that is selected, when the SelectedItem is bound, when the grid is first shown? You can see in the screenshot that the first cell of the first row is focused even though the third row is selected via binding. You can also see the properties that are set for the grid below.

As soon as a user clicks on another row in the grid, the outlining / focus on the first cell goes away and moves to the first cell of the row the user selected.

 


                    <telerik:RadGridView
                        x:Name="fieldsGrid"
                        HorizontalAlignment="Stretch"
                        VerticalAlignment="Stretch"
                        IsReadOnly="True"
                        AutoGenerateColumns="False"
                        SelectionMode="Single"
                        SelectionUnit="FullRow"
                        EnableLostFocusSelectedState="False"
                        ShowGroupPanel="False"
                        ShowSearchPanel="False"
                        SearchPanelCloseButtonVisibility="Collapsed"
                        RowIndicatorVisibility="Collapsed"
                        IsSynchronizedWithCurrentItem="True"
                        IsFilteringAllowed="True"
                        CanUserDeleteRows="False"
                        CanUserFreezeColumns="False"
                        ShowColumnSortIndexes="False"
                        MouseDoubleClick="InsertableRow_OnMouseDoubleClick"
                        ItemsSource="{Binding FieldsForBindingOnly, Mode=OneWay}"
                        SelectedItem="{Binding SelectedField, Mode=TwoWay}">

 

 

1 Answer, 1 is accepted

Sort by
0
Stenly
Telerik team
answered on 22 Nov 2024, 11:23 AM

Hello Stephen,

To achieve this requirement, you can subscribe to the Loaded event of RadGridView and manually set its CurrentCellInfo property. 

The following code snippet shows what I have in mind:

private void RadGridView_Loaded(object sender, RoutedEventArgs e)
{
    RadGridView radGridView = (RadGridView)sender;

    radGridView.CurrentCellInfo = new GridViewCellInfo(radGridView.SelectedItem, radGridView.Columns[0]);
}

When the RadGridView control initially loads, the following result will be present where the current item will be synchronized with the selected item:

I have attached a sample project for you to test.

Regards,
Stenly
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
Stephen
Top achievements
Rank 1
Answers by
Stenly
Telerik team
Share this question
or