David Smith

David Smith

  • NA
  • 2k
  • 0

WPF Delete Multiple Rows using Datagrid (ViewModel)

May 27 2015 3:42 AM
How to delete multiple base upon row select using the WPF datagrid through the view model. I do not want to handle delete through a Click event.
 
I want the databinding to take care of the multiple row select. This is what I have so far
 

<Grid VerticalAlignment="Stretch" Margin="0,0,0,0" HorizontalAlignment="Left">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" />
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="*" />
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
<!--<TabControl Grid.Row="0" Grid.Column="1" HorizontalAlignment="Stretch" VerticalAlignment="Stretch">

<DataGrid x:Name="ColorGrid" ItemsSource="{Binding ColorModelCollection}" AutoGenerateColumns="False">
<DataGrid.Columns>
<DataGridTextColumn Binding="{Binding ColorId}" Header="ColorId" Visibility="Hidden" />
<DataGridTextColumn Binding="{Binding ColorType}" Header="ColorType" />
<DataGridTextColumn Binding="{Binding ColorFilter}" Header="ColorFilter" Width="250"/>
<DataGridTextColumn Binding="{Binding ColorPath}" Header="ColorRoute" Width="250"/>
<DataGridCheckBoxColumn Binding="{Binding Color1, UpdateSourceTrigger=PropertyChanged}" Header=" 1:Color" Width="100" CanUserResize="False" />
<DataGridCheckBoxColumn Binding="{Binding Color2, UpdateSourceTrigger=PropertyChanged}" Header=" 2:Color" Width="100" CanUserResize="False" />
<DataGridCheckBoxColumn Binding="{Binding Color3, UpdateSourceTrigger=PropertyChanged}" Header=" 3:Color" Width="100" CanUserResize="False" />
<DataGridTemplateColumn>
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<Button Name="btnRemove">Remove</Button>
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>
</DataGrid.Columns>
</DataGrid>

</Grid>

 

Answers (2)