Set CurrentItem of GridView to embedded RadButton row

9 posts, 1 answers
  1. Sorin
    Sorin avatar
    7 posts
    Member since:
    Jan 2014

    Posted 05 Dec 2014 Link to this post

    Hello,

    Could you please specify how can a button placed in the CellTemplate tag of a GridViewDataColumn (1) map the row in which the button is placed at click?
    In my implementation, I need to embed buttons in each row of a specific column in order to remove those rows. The button is bound to a command which removes the CurrentItem from the ListCollectionView bound to the GridView (2).
    However, clicking the embedded button doesn't mark its row as the selected one and the command removes the row which is marked as Selected in the GridView (by clicking on one of the columns which don't embed the mentioned button).
    In conclusion, the button is supposed to mark its row as selected when clikcked, in order for the bound Command to remove the desired row, without having to click on the row (thus selecting it) and then click on the button.




  2. Sorin
    Sorin avatar
    7 posts
    Member since:
    Jan 2014

    Posted 05 Dec 2014 in reply to Sorin Link to this post

    <telerik:GridViewDataColumn.CellTemplate>
                            <DataTemplate>
                                <telerik:RadButton
                                   Content="Remove" 
                                   VerticalAlignment="Center"
                                   VerticalContentAlignment="Center"
                                   Height="21"
                                   Width="Auto"
                                   IsEnabled="{Binding DataContext.IsEditState, RelativeSource={RelativeSource AncestorType=UserControl}}" 
                                   Command="{Binding Path=DataContext.RemoveCurrentBlockedIntervalCommand, RelativeSource={RelativeSource AncestorType=UserControl}}"
                                   Visibility="Visible" />
                            </DataTemplate>
                        </telerik:GridViewDataColumn.CellTemplate>
  3. Sorin
    Sorin avatar
    7 posts
    Member since:
    Jan 2014

    Posted 08 Dec 2014 Link to this post

    Posted above is the RadGridView column's source code.    
  4. Boris
    Admin
    Boris avatar
    276 posts

    Posted 08 Dec 2014 Link to this post

    Hello Sorin,

    A possible way to avoid the need of selecting the row and delete it directly when you click the button is to take advantage of the built in RadGridViewCommands, like so:

    <telerik:GridViewColumn>
      <telerik:GridViewColumn.CellTemplate>
         <DataTemplate>
             <telerik:RadButton Content="Delete" Command="telerik:RadGridViewCommands.Delete" CommandParameter="{Binding}" />
         </DataTemplate>
      </telerik:GridViewColumn.CellTemplate>
    </telerik:GridViewColumn>

    For more information about the RadGridViewCommands, you can check the Overview and Implementation articles of the Commands section of our documentation about RadGridView.

    Please let us know if this approach is suitable to your scenario.

    Regards,
    Boris
    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.

     
  5. Sorin
    Sorin avatar
    7 posts
    Member since:
    Jan 2014

    Posted 08 Dec 2014 in reply to Boris Link to this post

    Hello again,

    I created a button in the Data Template exactly as you described, but the Delete buttons are disabled. Not even setting IsEnabled to true doesn't enable the buttons. Any idea why?

    Thanks!
  6. Answer
    Boris
    Admin
    Boris avatar
    276 posts

    Posted 09 Dec 2014 Link to this post

    Hi Sorin,

    Another possible reason for the buttons to be disabled, even it their IsEnabled property is set to True, is that the entire RadGridView is disabled as well. In order to investigate further why this behavior could you please provide us with a small runnable project that reproduces the issue ?

    Please keep in mind that to send us the project you will need to open a new support ticket.

    Regards,
    Boris
    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.

     
  7. Sorin
    Sorin avatar
    7 posts
    Member since:
    Jan 2014

    Posted 10 Dec 2014 in reply to Boris Link to this post

    Hello again,

    The GridView is definetly enabled. Furthermore, there's another button (Add) placed inside the GridView header which is bound to our enabled property (VM side) and works correctly. The DataContext of the buttons is set exactly the same.
    When the specified command is removed from the Remove button, the enabled VM property is bound as intended. So the command seems to disable the button at all times.
    Attached you can find a .png which illustrates the above mentioned scenario.
  8. Sorin
    Sorin avatar
    7 posts
    Member since:
    Jan 2014

    Posted 10 Dec 2014 in reply to Sorin Link to this post

    +attachment
  9. Boris
    Admin
    Boris avatar
    276 posts

    Posted 12 Dec 2014 Link to this post

    Hello Sorin,

    In order to investigate further why this behavior occurs could you please provide us with a small runnable project that reproduces the issue ? By providing us with such a project we will be able to debug it on our side and inform you of our findings. In addition, if you are not entirely sure how to isolate it, you can check this Isolating a problem in a sample project  blog post for some guidance.

    Regards,
    Boris
    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.

     
Back to Top