Click here to Skip to main content
15,914,488 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Quote:
Okay, I'm Adding Items To Two ListBoxes During A Function, One For The Normal Plain Text, & Another For The MD5 Hash.


PasswordList.Items.Add(Password.Text)
MD5ListBox.Items.Add(MD5.Text)


Quote:
Everything Is Proceeding Successfully, Both The Plain Text & MD5 Hashes Are Adding To ListBoxes Perfectly, But When Removing The Same Indices Which I'm Removing In The Password List, I Want To Remove In The MD5 List Too. It's Functionally Completely When I Remove One Seleceted Item, But When I Remove More Than One Seleceted Item In The Password List I Get An Error When Removing From The MD5List. I'm Basically Getting The Selected Indices In The Password List, & Using A Loop To Remove The Same Indices Integers Selected In Password List, To Remove In MD5 List.


 If PasswordList.SelectedItems.Count = 1 Then

     Dim KeyNumber As Integer = PasswordList.SelectedIndices(0)

     MD5ListBox.Items.RemoveAt(KeyNumber)

     PasswordList.Items.Remove(PasswordList.SelectedItem)

 Elseif PasswordList.SelectedItems.Count > 1

     Dim KeyNumber5 = rdpForm.PasswordList.SelectedIndices

     For Each indx5 As Integer In KeyNumber5

         rdpForm.MD5ListBox.Items.RemoveAt(indx5)

     Next

     Dim selectedItems = (From I In rdpForm.PasswordList.SelectedItems).ToList

     For Each selectedItem In selectedItems

         rdpForm.PasswordList.Items.Remove(selectedItem)

     Next

End If


Quote:
There's Always An Error When Removing Indices In The MD5List, But Here's An Example.

ERROR: System.ArgumentOutOfRangeException: 'InvalidArgument=Value of '21' is not valid for 'index'. Parameter name: index' Items In ListBoxes(40), Attempting To Remove Indices(2-39)


What I have tried:

I Can't Really Figure Out Another Way.
Posted
Updated 10-May-21 8:13am
v2

1 solution

You need to "reverse" KeyNumber5; or read in reverse.

You're deleting by "index". In the "forward" direction, after the first (index) delete, all subsequent ones are invalid (due to shifting).

Remove by "key" instead; if you don't do it in reverse.
 
Share this answer
 
Comments
Member 14606125 10-May-21 15:30pm    
Okay, I'm Getting An Understanding, Can You Give Me A Code Example, I Would Appreciate It. I'm Really Trying To Finish This Project.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900