locked
如何实现删除选定的listview 中的item? RRS feed

  • 问题

  • 我想要实现删除checkcox已经被勾选的item,不知道如何去实现。我是新人,能讲解的稍微详细下吗?多谢~
    2015年7月2日 2:52

答案

  • Hello,

    >>如何实现删除选定的listview 中的item 在windows runtime app里,listview有提供多选的功能,并不需要再加一个checkbox来标明已选中items,在你XMAL里,把listview的selectedmode设成Multiple,然后可以触发一个button click事件来删除选中的items。这里我做了个demo你可以试下:

    XAML:

    <Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
    
            <StackPanel>
                <ListView x:Name="ListViewMultiSelector" SelectionMode="Multiple" FontSize="50">
                    <ListViewItem>Dog0</ListViewItem>
                    <ListViewItem>Dog1</ListViewItem>
                    <ListViewItem>Dog2</ListViewItem>
                    <ListViewItem>Dog3</ListViewItem>
                    <ListViewItem>Dog4</ListViewItem>
                    <ListViewItem>Dog5</ListViewItem>
                </ListView>
    
                <Button Name="Delete" Content="Delete" FontSize="50"  Click="Delete_Click"/>
            </StackPanel>
    
    
        </Grid>
    

    Button click 事件代码:

    private void Delete_Click(object sender, RoutedEventArgs e)
            {
                List<object> preparateremoveitems = new List<object>();
    
                foreach (var item in this.ListViewMultiSelector.SelectedItems)
                {
                    preparateremoveitems.Add(item);
                }
    
                foreach (var item in preparateremoveitems)
                {
                    this.ListViewMultiSelector.Items.Remove(item);
                }
            }
    

    Regards.


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.


    2015年7月3日 6:04
    版主
  • 使用ListView自带的多选功能,详见Demo:

    XAML ListView and GridView essentials sample

    关于删除,是动态绑定的问题,建议楼主了解下绑定的相关知识。


    专注于Windows Phone

    2015年7月6日 3:39
    版主

全部回复

  • Hello,

    >>如何实现删除选定的listview 中的item 在windows runtime app里,listview有提供多选的功能,并不需要再加一个checkbox来标明已选中items,在你XMAL里,把listview的selectedmode设成Multiple,然后可以触发一个button click事件来删除选中的items。这里我做了个demo你可以试下:

    XAML:

    <Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
    
            <StackPanel>
                <ListView x:Name="ListViewMultiSelector" SelectionMode="Multiple" FontSize="50">
                    <ListViewItem>Dog0</ListViewItem>
                    <ListViewItem>Dog1</ListViewItem>
                    <ListViewItem>Dog2</ListViewItem>
                    <ListViewItem>Dog3</ListViewItem>
                    <ListViewItem>Dog4</ListViewItem>
                    <ListViewItem>Dog5</ListViewItem>
                </ListView>
    
                <Button Name="Delete" Content="Delete" FontSize="50"  Click="Delete_Click"/>
            </StackPanel>
    
    
        </Grid>
    

    Button click 事件代码:

    private void Delete_Click(object sender, RoutedEventArgs e)
            {
                List<object> preparateremoveitems = new List<object>();
    
                foreach (var item in this.ListViewMultiSelector.SelectedItems)
                {
                    preparateremoveitems.Add(item);
                }
    
                foreach (var item in preparateremoveitems)
                {
                    this.ListViewMultiSelector.Items.Remove(item);
                }
            }
    

    Regards.


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.


    2015年7月3日 6:04
    版主
  • 使用ListView自带的多选功能,详见Demo:

    XAML ListView and GridView essentials sample

    关于删除,是动态绑定的问题,建议楼主了解下绑定的相关知识。


    专注于Windows Phone

    2015年7月6日 3:39
    版主