This is a migrated thread and some comments may be shown as answers.

GridView: Binding Multiple Selection on a CommandParameter

1 Answer 370 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Howell
Top achievements
Rank 1
Howell asked on 16 Aug 2011, 04:05 PM
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?

1 Answer, 1 is accepted

Sort by
0
Vanya Pavlova
Telerik team
answered on 18 Aug 2011, 09:37 AM
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 >>

Tags
GridView
Asked by
Howell
Top achievements
Rank 1
Answers by
Vanya Pavlova
Telerik team
Share this question
or