GridView: Binding Multiple Selection on a CommandParameter

2 posts, 0 answers
  1. Howell
    Howell avatar
    10 posts
    Member since:
    Jul 2012

    Posted 16 Aug 2011 Link to this post

    I need to have a context menu on a gridview whereby the user can select multiple rows on the gridview and right-clicked on it then the user can change the Status of the row via the iCommand.

    <telerik:RadGridView Name="rcGridView" Grid.Row="0" Margin="15" ItemsSource="{Binding Users, NotifyOnSourceUpdated=True,  
    UpdateSourceTrigger=PropertyChanged, Mode=TwoWay}" AutoGenerateColumns="False" ClipToBounds="False"  
    SelectionMode="Extended" VerticalAlignment="Stretch"   telerik:StyleManager.Theme="Summer" RowHeight="20"  
    RowIndicatorVisibility="Collapsed" CanUserInsertRows="False"  CanUserDeleteRows="False"  HorizontalAlignment="Left"  
    FontSize="11"  ClipboardCopyMode="All" ClipboardPasteMode="AllSelectedCells,Default"  SelectionUnit="FullRow" CanUserFreezeColumns="False">     
      <telerik:RadContextMenu.ContextMenu>         
        <telerik:RadContextMenu>             
            <telerik:RadContextMenu.Items>                 
                <telerik:RadMenuItem Header="Approve" Command="{Binding UpdateSourceTrigger=Default, NotifyOnSourceUpdated=True,  
                        RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type telerik:RadContextMenu}},Path=DataContext.StatChgtoApproveCommand}"  
                        CommandParameter="{Binding ElementName=rcGridView, Path=SelectedItems}"  />                 
                <telerik:RadMenuItem Header="Hold" Command="{Binding UpdateSourceTrigger=Default, NotifyOnSourceUpdated=True,  
                        RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type telerik:RadContextMenu}},Path=DataContext.StatChgtoHoldCommand}"
                        CommandParameter="{Binding ElementName=rcGridView, Path=SelectedItems}"  />
                <telerik:RadMenuItem Header="Reject" Command="{Binding UpdateSourceTrigger=Default, NotifyOnSourceUpdated=True,  
                        RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type telerik:RadContextMenu}},Path=DataContext.StatChgtoRejectCommand}"
                        CommandParameter="{Binding ElementName=rcGridView, Path=SelectedItems}" />  
            </
    telerik:RadContextMenu.Items>         
        </telerik:RadContextMenu>     
     </telerik:RadContextMenu.ContextMenu>     
     <telerik:RadGridView.Columns
        <telerik:GridViewDataColumn Header="ID" DataMemberBinding="{Binding ID}" />         
        <telerik:GridViewDataColumn Header="Name" DataMemberBinding="{Binding Name}" />
        <
    telerik:GridViewDataColumn Header="Status" 
    DataMemberBinding="{Binding Status}" />     
     </telerik:RadGridView.Columns>
    </
    telerik:RadGridView>

    Unfortunately, when the user click on the item context menu the command will trigger an iCommand and CommanParameter is null. The CommandParameter should be the multiple selected rows on the gridview. Is there a way to make this work?
  2. Vanya Pavlova
    Admin
    Vanya Pavlova avatar
    2019 posts

    Posted 18 Aug 2011 Link to this post

    Hello Howell,


     
    You may expose SelectedItems / SelectedItems properties of your ViewModel and synchronize it using attached behaviors as demonstrated in the following blog post "How To: Synchronize your UI selected items with your data context using MVVM and Blend behaviors for Silverlight and WPF".




    Regards,
    Vanya Pavlova
    the Telerik team

    Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get now >>

Back to Top