3
votes

I've got a telerik RadGridView with several rows and columns. One of the columns contain a button, which call a command of my ViewModel.

Here's my columns description:

<telerikGrid:RadGridView.Columns>

   <telerikGrid:GridViewColumn Width="32" IsVisible="{Binding IsAvailable}">
      <telerikGrid:GridViewColumn.CellTemplate>
          <DataTemplate> 
              <telerik:RadButton Width="24" Height="24" x:Name="AddItemToList"                                                    
             Command="{Binding AddItemToListCommand, RelativeSource={RelativeSource  Mode=FindAncestor, AncestorType={x:Type UserControl}}}">

                  <Image Stretch="Uniform" Source="Images/add.png" HorizontalAlignment="Center" />
               </telerik:RadButton>
            </DataTemplate>
        </telerikGrid:GridViewColumn.CellTemplate>
      </telerikGrid:GridViewColumn>

      <telerikGrid:GridViewDataColumn DataMemberBinding="{Binding Name}"/>
      <telerikGrid:GridViewDataColumn DataMemberBinding="{Binding ConName}"/>
      <telerikGrid:GridViewDataColumn DataMemberBinding="{Binding DisName}"/>

</telerikGrid:RadGridView.Columns>

When a row is selected and I click on the button, the good values are sent to the ViewModel. But, my problem is that, if I click on the button of another row (not my selected row), it does not select the row and thus, send the wrong values to VM (the value of the selected row is sent)!

How do I force the row selection to select the row containing the button I am clicking? It should actually be done in my XAML, before my command is executed.

Hope its clear enough. I want my focus to be set on the row containing the button I am clicking.

1
To simplify, I want to select the row on Button click, before the command is executed. - Nadeem_MK

1 Answers

3
votes

You can send the Selecteditem as the CommandParameter of AddItemToListCommand CommandParamter="{Binding}". So you will get row datacontext i.e the item on which button was clicked.

Thanks