删除多个选定的行 [英] delete multiple selected rows

查看:80
本文介绍了删除多个选定的行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好

我有一个绑定到数据集的ListView.用户具有选择多行的能力.我想单击一个按钮时,删除所有选中的项目.为此,我使用了一个循环,但收到错误消息:操作无效 使用ItemsSource时.而是使用ItemsControl.ItemsSource访问和修改元素. 代码看起来很

I have a ListView that is bound to a dataset. The user has ability to select multiple rows. I would like when a button is clicked, delete all selected items. For that I use a loop but get error message: Operation is not valid while ItemsSource is in use. Access and modify elements with ItemsControl.ItemsSource instead. The code looks

If ListView1.SelectedItems.Count > 0 Then
  For i As Integer = ListView1.SelectedItems.Count - 1 To 0 Step -1
   ListView1.Items.Remove(ListView1.SelectedItems(i))
  Next
End If

推荐答案

大家好.

我的ListView有chechbox列,我想在ListView中选择一些行,然后通过单击Delete按钮将其删除.那就是删除程序的代码.

My ListView has chechbox column and I would like to select some rows in ListView and delete them by click Delete button. That is code of Delete procedure.

  Private Sub DeleteSvcButton_Click(ByVal sender As System.Object, ByVal e As System.Windows.RoutedEventArgs) Handles DeleteSvcButton.Click  
  If Not IsNothing(Me.ListView1.SelectedValue) Then
   If ListView1.SelectedItems.Count > 0 Then
    For i As Integer = 1 To ListView1.SelectedItems.Count
     Dim TestDataRow As System.Data.DataRowView
     TestDataRow = ListView1.SelectedItems(i - 1)
     Service_Id = Me.ListView1.SelectedValue
    Next
   End If

   If MsgBox("Are you sure you want to delete this row", MsgBoxStyle.YesNo, "Are You Sure?") = MsgBoxResult.Yes Then
    Me.cvService.RemoveAt(Me.cvService.CurrentPosition)
    Me.ServicesTableAdapter.Update(Me.TestDataSet.Service)
   End If
  End If
 End Sub


这篇关于删除多个选定的行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆