Go Back  Xtreme Visual Basic Talk > Visual Basic .NET (2002/2003/2005/2008, including Express editions) > .NET General > delete from Listbox


Reply
 
Thread Tools Display Modes
  #1  
Old 02-25-2009, 02:21 PM
Finnibusa121 Finnibusa121 is offline
Newcomer
 
Join Date: Feb 2009
Posts: 7
Unhappy delete from Listbox


Hi. Seems I have some problems when it comes to delete stuff from my listbox.

If someone figures it out for me, please let me know.

Here is the code:

Public Class Form1

Private Sub TextBox1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs)
End Sub

Private Sub GroupBox1_Enter(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles GroupBox1.Enter
End Sub

Private Sub ListBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs)
End Sub
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
End Sub

Private Sub Label7_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Label7.Click
End Sub

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
End Sub

Private Sub TextBox6_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox6.TextChanged
End Sub

Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
''Fjerner tekst i ListBox1'
Dim Item As String
Item = ListBox1.Text
ListBox1.Items.Remove(Item)
End Sub

Private Sub CheckBox1_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CheckBox1.CheckedChanged
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
'Sier i fra om, når checkbox er krysset av, lagre teksten i listbox'
If CheckBox1.Checked = True Then
Dim item As String
item = TextBox1.Text
ListBox1.Items.Add(item)
End If
End Sub

Private Sub Label9_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Label9.Click

End Sub

Private Sub TextBox2_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox2.TextChanged

End Sub

Private Sub TextBox3_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox3.TextChanged

End Sub

Private Sub TextBox4_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox4.TextChanged

End Sub

Private Sub MaskedTextBox1_MaskInputRejected(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MaskInputRejectedEventArgs)

End Sub

Private Sub Button2_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click

End Sub
Private Sub ComboBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ComboBox1.SelectedIndexChanged

End Sub

Private Sub TextBox5_TextChanged_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox5.TextChanged
End Sub

Private Sub ListBox1_SelectedIndexChanged_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ListBox1.SelectedIndexChanged
'Putter text i valgt text fil'
TextBox6.Text = ListBox1.SelectedItem.ToString
End Sub
End Class

------------------------------
Getting error:

System.NullReferenceException was unhandled
Message="Objektreferanse er ikke satt til en objektforekomst."
Source="Rcon oldis"
StackTrace:
ved WindowsApplication1.Form1.ListBox1_SelectedIndexChanged_1(Object sender, EventArgs e) i C:\Documents and Settings\Finn\Mine dokumenter\Visual Studio 2008\Projects\Rcon oldis\Rcon oldis\Form1.vb:linje 73
ved System.Windows.Forms.ListBox.OnSelectedIndexChanged(EventArgs e)
ved System.Windows.Forms.ListBox.NativeRemoveAt(Int32 index)
ved System.Windows.Forms.ListBox.ObjectCollection.RemoveAt(Int32 index)
ved System.Windows.Forms.ListBox.ObjectCollection.Remove(Object value)
ved WindowsApplication1.Form1.Button3_Click(Object sender, EventArgs e) i C:\Documents and Settings\Finn\Mine dokumenter\Visual Studio 2008\Projects\Rcon oldis\Rcon oldis\Form1.vb:linje 27
ved System.Windows.Forms.Control.OnClick(EventArgs e)
ved System.Windows.Forms.Button.OnClick(EventArgs e)
ved System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent)
ved System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
ved System.Windows.Forms.Control.WndProc(Message& m)
ved System.Windows.Forms.ButtonBase.WndProc(Message& m)
ved System.Windows.Forms.Button.WndProc(Message& m)
ved System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
ved System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
ved System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
ved System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
ved System.Windows.Forms.Application.ComponentManager.System.Windows.Forms .UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(Int32 dwComponentID, Int32 reason, Int32 pvLoopData)
ved System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int 32 reason, ApplicationContext context)
ved System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
ved System.Windows.Forms.Application.Run(ApplicationContext context)
ved Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase. OnRun()
ved Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase. DoApplicationModel()
ved Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase. Run(String[] commandLine)
ved WindowsApplication1.My.MyApplication.Main(String[] Args) i 17d14f5c-a337-4978-8281-53493378c1071.vb:linje 81
ved System.AppDomain._nExecuteAssembly(Assembly assembly, String[] args)
ved System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
ved Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
ved System.Threading.ThreadHelper.ThreadStart_Context(Object state)
ved System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
ved System.Threading.ThreadHelper.ThreadStart()
InnerException:
----------------------------------------
when trying to delete something.
Reply With Quote
  #2  
Old 02-25-2009, 03:00 PM
hawkvalley1's Avatar
hawkvalley1 hawkvalley1 is offline
Centurion
 
Join Date: May 2008
Location: Denver, CO USA
Posts: 190
Default

If you want to delete an item in the listbox using the text in a textbox use this:
Code:
If ListBox1.Items.Contains(TextBox1.Text) Then
      ListBox1.Items.Remove(TextBox1.Text)
    Else
      MsgBox("No items found!")
End If
'or to delete the item by selecting it
If ListBox1.SelectedIndex > -1 Then
    ListBox1.Items.RemoveAt(ListBox1.SelectedIndex)
End If
Reply With Quote
  #3  
Old 02-25-2009, 04:17 PM
Finnibusa121 Finnibusa121 is offline
Newcomer
 
Join Date: Feb 2009
Posts: 7
Default

Quote:
Originally Posted by hawkvalley1 View Post
If you want to delete an item in the listbox using the text in a textbox use this:
Code:
If ListBox1.Items.Contains(TextBox1.Text) Then
      ListBox1.Items.Remove(TextBox1.Text)
    Else
      MsgBox("No items found!")
End If
'or to delete the item by selecting it
If ListBox1.SelectedIndex > -1 Then
    ListBox1.Items.RemoveAt(ListBox1.SelectedIndex)
End If
Am I correct if that line goes under Button?_click?
I have been doing VB 2008 for 2 days, so still a noob :P
Reply With Quote
  #4  
Old 02-25-2009, 04:39 PM
hawkvalley1's Avatar
hawkvalley1 hawkvalley1 is offline
Centurion
 
Join Date: May 2008
Location: Denver, CO USA
Posts: 190
Default

Yes, if you have a Button - name it something like "Remove" or "Delete" or whatever makes sense to you.
Reply With Quote
  #5  
Old 02-25-2009, 05:05 PM
Finnibusa121 Finnibusa121 is offline
Newcomer
 
Join Date: Feb 2009
Posts: 7
Default

Sweet If I want my app to connect to internet, do I need it to run true SQL first or can I just code it.
I wanna make a program that connects to my game server.
You don't know how to configure that? Been searching the net for 7 hours today, and can't find much that makes sence to me.

Thanks for all the help btw
Reply With Quote
  #6  
Old 02-27-2009, 10:14 AM
hawkvalley1's Avatar
hawkvalley1 hawkvalley1 is offline
Centurion
 
Join Date: May 2008
Location: Denver, CO USA
Posts: 190
Default

That would be a new question - so a new post, and see if someone if familiar with that, as I am not. Your welcome...
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
 
 
-->