Salut à tous j'ai ce code pour vérifier si un élément d'une zone de texte est dans une liste et il me donne l'erreur en bas. Des idées ce que je fais mal? Je l'ai copié d'une autre partie de mon projet et cela fonctionnait pour cette partie donc je ne peux pas voir ce qui est mal.Vérification d'un ensemble d'éléments de la liste par rapport à une zone de texte vb.net
If LocationsSearchTextBox.Text <> "" And LocationListBox.Items.Count > 0 Then
tempInt = 0
While (tempInt < ClientListBox.Items.Count)
If LocationListBox.Items(tempInt).ToString.Contains(LocationsSearchTextBox.Text) = False Then
LocationListBox.Items.RemoveAt(tempInt)
End If
tempInt += 1
End While
End If
System.ArgumentOutOfRangeException était unhandled message = "InvalidArgument = valeur de '2' est pas valide pour 'index' Nom du paramètre: index." ParamName = "index" Source = "System.Windows. formulaires » STACKTRACE: à System.Windows.Forms.ListBox.ObjectCollection.get_Item (indice Int32) à AuctioneerProject.Viewing.LocationsSearchTextBox_KeyPress (sender d'objets, KeyPressEventArgs e) dans C: \ Users \ admin \ Desktop \ Auctioneers \ AuctioneerProject \ AuctioneerProject \ Viewing.vb: ligne 301 à System.Windows.Forms.Control.OnKeyPress (KeyPressEventArgs e) à System.Windows.Forms.Control.ProcessKeyEventArgs (message & m) à System.Windows.Forms.Control.ProcessKeyMessage (message & m) à System.Windows.Forms.Control.WmKeyChar (message & m) au système .Windows.Forms.Control.WndProc (message & m) à System.Windows.Forms.TextBoxBase.WndProc (message & m) à System.Windows.Forms.TextBox.WndProc (message & m) à System.Windows .Forms.Control.ControlNativeWindow.OnMessage (Message & m) à System.Windows.Forms.Control.ControlNativeWindow.WndProc (Message & m) à System.Windows.Forms.NativeWindow.DebuggableCallback (IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam) à System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW (MSG & msg) à System.Windows.Forms.Application. ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop (Int32 dwComponentID, raison Int32, Int32 pvLoopData) à System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner (raison la Int32, le contexte ApplicationContext) à System.Windows.Forms .Application.ThreadContext.RunMessageLoop (raison Int32, contexte ApplicationContext) à System.Windows.Forms.Application.Run (contexte ApplicationContext) à Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.OnRun() à Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.DoApplicationModel() à Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.Run (String [] commandLine) à AuctioneerProject.My.MyApplication.Main (String [] Args) dans 17d14f5c-a337- 4978-8281-53493378c1071.vb: ligne 81 à System.AppDomain._nExecuteAssembly (Assembly assembly, String [] args) à System.AppDomain.ExecuteAssembly (String assemblyFile, Evidence assemblySecurity, String [] args) à Microsoft.VisualStudio .HostingProcess.HostProc.RunUsersAssembly() at System.Threading.ThreadHelper.ThreadStart_Context (état de l'objet) à System.Threading.ExecutionContext.Run (ExecutionContext executionContext, rappel ContextCallback, état de l'objet) at Syst em.Threading.ThreadHelper.ThreadStart() InnerException:
C'est très juste merci –
Je l'ai fait un peu différemment si je ju st Si LocationListBox.Items (tempInt) .ToString.Contains (LocationsSearchTextBox.Text) = False Then LocationListBox.Items.RemoveAt (tempInt) autre tempInt + = 1 End If –
Vous devez certainement le faire de cette façon si vous êtes à l'école, parce que vous voulez toujours être correct mais ** pas ** le faire comme ils l'attendent. –