大家好我有這個代碼來檢查一個文本框中的項目是否在列表框中,它給我在底部的錯誤。任何想法我做錯了什麼?我從我的項目的另一部分複製它,它正在爲那部分工作,所以我不能看到什麼是錯的。檢查一組文本框中的列表框項目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了未處理 消息= 「的 '2' InvalidArgument =值是無效的 '索引' 參數名:索引」 PARAMNAME = 「索引」 源=「System.Windows。表單「 Stackrrace: 位於C:\ Users \ admin \ Desktop \ Auctioneers \ AuctioneerProject \中的AuctioneerProject.Viewing.LocationsSextTextBox_KeyPress(System.Windows.Forms.ListBox.ObjectCollection.get_Item(Int32 index) ) AuctioneerProject \ Viewing.vb:line 301 at System.Windows.Forms.Control.OnKeyPress(KeyPressEventArgs e) 在System.Windows.Forms.Control.ProcessKeyEventArgs(消息&米) 在System.Windows.Forms.Control.ProcessKeyMessage(消息&米) 在System.Windows.Forms.Control.WmKeyChar(消息&米) 在系統.Windows.Forms.Control.WndProc(消息&米) 在System.Windows.Forms.TextBoxBase.WndProc(消息&米) 在System.Windows.Forms.TextBox.WndProc(消息&米) 在System.Windows .Forms.Control.ControlNativeWindow.OnMessage(Message & m) at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message & m) 在System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr的的HWND,MSG的Int32,IntPtr的WPARAM,IntPtr的LPARAM) 在System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG & MSG) 在System.Windows.Forms.Application。 Component.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(Int32 dwComponentID,Int32 reason,Int32 pvLoopData) at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason,ApplicationContext context) at System.Windows.Forms .Application.ThreadContext.RunMessageLoop(Int32 reason,ApplicationContext context) at System.Windows.Forms.Application.Run(ApplicationContext context) at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.OnRun() 在Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.DoApplicationModel() at AuctioneerProject.My.MyApplication.Main(String [] Args)在Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.Run(String [] commandLine) 17d14f5c-a337- 4978-8281-53493378c1071.vb:line 81 at System.AppDomain._nExecuteAssembly(Assembly assembly,String [] args) at System.AppDomain.ExecuteAssembly(String assemblyFile,Evidence assemblySecurity,String [] args) at Microsoft.VisualStudio System.Threading.ExecutionContext.Run(ExecutionContext executionContext,ContextCallback回調,對象狀態)下System.Threading.ThreadHelper.ThreadStart_Context(對象狀態) 在系統上.HostingProcess.HostProc.RunUsersAssembly() em.Threading.ThreadHelper.ThreadStart() InnerException:
這就是非常正確的感謝 – 2010-03-23 15:09:09
雖然我ju做了一點點不同ST 如果LocationListBox.Items(tempInt).ToString.Contains(LocationsSearchTextBox.Text)= false,那麼 LocationListBox.Items.RemoveAt(tempInt) 其他 tempInt + = 1點 結束如果 – 2010-03-23 15:17:45
你絕對應該這樣做的,如果你'在學校,因爲你總是想要正確,但**不是按照他們期望的方式去做。 – 2010-03-23 16:46:15