RadGridView SelectedItem does not update correctly

2 posts, 0 answers
  1. Jerry
    Jerry avatar
    7 posts
    Member since:
    Mar 2013

    Posted 27 Oct 2014 Link to this post

    I'm using the RadGridView control to display an Observable collection. I also use SelectedItem="{Binding Model.CurrentRow, Mode=TwoWay}" to track which item in the list the grid pointer is on.

    The first column in the grid has a textbox so the user can change the value in the grid. I subscribe to a property change event to validate the content in the textbox.

    The other columns in the grid are not editable.

    ----
    The problem:
    ----
    When I click on any non-editable column in the grid, the grid Row highlights correctly and the "Model.CurrentRow" updates correctly. However, when I click on a textbox in the first column on a non selected row, that row does NOT receive focus. The grid row focus stays on the prevously selected row, and the "Model.CurrentRow" does not update.

    How can I make the grid row focus on the selected row when i click on an editable textbox in the grid?

    My partial RadGridView xaml:

    <gridControls:RadGridView
                    ........
                    AutoGenerateColumns="False"
                    CanUserDeleteRows="False"
                    CanUserFreezeColumns="False"
                    CanUserInsertRows="False"
                    IsFilteringAllowed="False"
                    IsReadOnly="False"
                    RowIndicatorVisibility="Collapsed"
                    SelectionUnit="FullRow"
                    ShowGroupPanel="False"
                    ItemsSource="{Binding Model.MyList}"
                    SelectedItem="{Binding Model.CurrentRow, Mode=TwoWay}">

    <gridControls:RadGridView.Columns>

       <gridControls:GridViewColumn
        Header="Company Name"
        IsReadOnly="True"
       Width="200" >
        <gridControls:GridViewColumn.CellTemplate>
         <DataTemplate>
           <TextBox Text="{Binding CompanyName, Mode=TwoWay}"/>
         </DataTemplate>
         </gridControls:GridViewColumn.CellTemplate>
        </gridControls:GridViewColumn>

                            <gridControls:GridViewDataColumn
                            DataMemberBinding="{Binding CustomerType}"
                            Header="Customer Type"
                            IsReadOnly="True"
                            Width="125"
                            />
    ...........

  2. Boris
    Admin
    Boris avatar
    276 posts

    Posted 29 Oct 2014 Link to this post

    Hi Jerry,

    Generally RadGridView supports selection out-of-the-box. However, in your case, you want to perform this action using a control placed in CellTemplate of the column(the TextBox).  If you click on the cell which contains the control, you will actually click in the TextBox instead of GridViewRow/GridViewCell, so RadGridView's selection logic will not work. 

    For more information about CellTemplate / CellEditTemplate you can check the Setting CellTemplate and CellEditTemplate documentation article.

    I hope this helps.

    Regards,
    Boris Penev
    Telerik
     

    Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

     
  3. DevCraft banner
Back to Top