Reputation: 11615
I would like to be able to select an item that is bound to my gridview and press the delete button, which would delete the item from the observable collection to which the gridview is bound to.
<ListView Height="166" HorizontalAlignment="Left" Margin="12,290,0,0" Name="listView1" VerticalAlignment="Top" Width="636" ItemsSource="{Binding SearchTerms}" KeyUp="SearchTermsGrid_KeyPressed">
<ListView.View>
<GridView x:Name="SearchTermsGrid">
<GridViewColumn Width="155" Header="Search Term" DisplayMemberBinding="{Binding Name}"/>
<GridViewColumn Width="90" Header="Status" DisplayMemberBinding="{Binding Status}"/>
<GridViewColumn Width="60" Header="Count" DisplayMemberBinding="{Binding NumberToDownload}"/>
<GridViewColumn Width="60" Header="Size" DisplayMemberBinding="{Binding Size}"/>
<GridViewColumn Width="60" Header="Type" DisplayMemberBinding="{Binding Type}"/>
</GridView>
</ListView.View>
</ListView>
ObservableCollection<SearchTerm> _searchTerms = new ObservableCollection<SearchTerm>();
public ObservableCollection<SearchTerm> SearchTerms
{
get
{
return _searchTerms;
}
}
private void SearchTermsGrid_KeyPressed(object sender, KeyEventArgs e)
{
if (e.Key == Key.Delete)
{
//I dunno, this might be a bad approach.
}
}
Upvotes: 0
Views: 2533
Reputation: 192457
does this not work:?
this._searchTerms.Remove(this.listView1.SelectedItem);
Upvotes: 2