开发者

Delete Items in an ObservableCollection That are Bound to A GridView

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 == 开发者_StackOverflow中文版Key.Delete)
    {
        //I dunno, this might be a bad approach.
    }
}


does this not work:?

this._searchTerms.Remove(this.listView1.SelectedItem);
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜