Answered by:
Delete items of ListView wpf application (Vb.NEt)

Question
-
Hi everybody,
I need to delete some items in my ListView (wpf application vb).
For i As Integer = ListView1.SelectedItems.Count - 1 To 0 Step -1
ListView1.SelectedItems(i).Remove()
NextWhen i write this code: the system give me this error:
An unhandled exception of type 'System.MissingMemberException' occurred in PresentationFramework.dll
Additional information: Le membre public 'Remove' du type 'ListAcquis' est introuvable.What is the problem there?
by the way, my listview is :
Private Sub ButtonAdd_Click(ByVal sender As System.Object, ByVal e As System.Windows.RoutedEventArgs) Handles ButtonAdd.Click
ListView1.Items.Add(New ListAcquis With
{
.TextBoxPasEnri = TextBoxPasEnri.Text,
.TextBoxModem = TextBoxModem.Text,
.TextBoxTypSate = TextBoxTypSate.Text,
.TextBoxAdresse = TextBoxAdresse.Text,
.TextBoxVoie = TextBoxVoie.Text})
'Effacer text dans les textbox
TextBoxVoie.Clear()- Moved by Gilles TOURREAU Monday, June 24, 2013 10:37 PM
Sunday, June 23, 2013 8:43 PM
Answers
-
Hi icor,
I am sorry for the mistake, var is the keyword in C# language. Please modify the code to:
Dim selectedItems = New System.Collections.ArrayList(ListView1.SelectedItems) 'get all the selected items For Each eachitem In selectedItems ListView1.Items.Remove(eachitem) Next
It works well for me.
Regards,
Lisa Zhu [MSFT]
MSDN Community Support | Feedback to us
Develop and promote your apps in Windows Store
Please remember to mark the replies as answers if they help and unmark them if they provide no help.- Marked as answer by Lisa Zhu Monday, July 8, 2013 11:29 AM
Wednesday, June 26, 2013 2:55 AM
All replies
-
Hi icor,
This exception represents that you are trying to remove the item which does not exist. Please refer to:http://msdn.microsoft.com/en-us/library/system.missingmemberexception.aspx.
From the code you provided, I think you add the listview item one by one, so you can give the following code a try:
Dim selectedItems = New System.Collections.ArrayList(ListView1.SelectedItems) 'get all the selected items For Each eachitem As var In selectedItems ListView1.Items.Remove(eachitem) Next
Regards,
Lisa Zhu [MSFT]
MSDN Community Support | Feedback to us
Develop and promote your apps in Windows Store
Please remember to mark the replies as answers if they help and unmark them if they provide no help.Tuesday, June 25, 2013 11:49 AM -
What about var?
I have a problem with var, the system says that is not declarated.
Thanks
Tuesday, June 25, 2013 3:35 PM -
Hi icor,
I am sorry for the mistake, var is the keyword in C# language. Please modify the code to:
Dim selectedItems = New System.Collections.ArrayList(ListView1.SelectedItems) 'get all the selected items For Each eachitem In selectedItems ListView1.Items.Remove(eachitem) Next
It works well for me.
Regards,
Lisa Zhu [MSFT]
MSDN Community Support | Feedback to us
Develop and promote your apps in Windows Store
Please remember to mark the replies as answers if they help and unmark them if they provide no help.- Marked as answer by Lisa Zhu Monday, July 8, 2013 11:29 AM
Wednesday, June 26, 2013 2:55 AM