Go Back  Xtreme Visual Basic Talk > Legacy Visual Basic (VB 4/5/6) > General > Removing listbox selected item


Reply
 
Thread Tools Display Modes
  #1  
Old 11-09-2003, 07:37 PM
knight knight is offline
Freshman
 
Join Date: Nov 2003
Posts: 28
Default Removing listbox selected item


How do I remove a user selected item in a listbox. Right now I have....

Code:
Private Sub Command3_Click()
lbo(RemoveItem) = lbo(SelectedItem)
End Sub
Where "lbo" is the name of the listbox. But that just yields a command button that does nothing at all.

I have anoter selected item that works similar (which works), where it gets the selected item in the listbox and sends it to the web browser

Code:
Private Sub Command1_Click()
Denlou.WebBrowser1.Navigate lbo(SelectedItem)
Unload favorites
End Sub
And I can't remove the equals sign because it returns "Expected: End of Statement"

Anyone know what to do?
Reply With Quote
  #2  
Old 11-09-2003, 07:40 PM
reboot's Avatar
reboot reboot is offline
Keeper of foo

Retired Moderator
* Guru *
 
Join Date: Nov 2001
Location: Graceland
Posts: 15,612
Default

lbo.RemoveItem lbo.ListIndex
__________________
~ Quod non mortiferum, fortiorem me facit ~

Avatar by lebb
Reply With Quote
  #3  
Old 11-09-2003, 07:41 PM
zanth_quareni's Avatar
zanth_quareni zanth_quareni is offline
Senior Contributor
 
Join Date: Aug 2003
Location: Tomarria
Posts: 905
Default

Remove the current .listindex
Code:
lblWhatever.RemoveItem lblWhatever.ListIndex
__________________
...leben ohne sinn...
Reply With Quote
  #4  
Old 11-09-2003, 07:41 PM
Illusionist's Avatar
Illusionist Illusionist is offline
Senior Contributor
 
Join Date: Oct 2003
Location: Chattanooga, TN USA
Posts: 1,069
Default

Code:
lbo.RemoveItem lbo.ListIndex

geeze got beat my 2 ppl!
Reply With Quote
  #5  
Old 11-09-2003, 07:45 PM
knight knight is offline
Freshman
 
Join Date: Nov 2003
Posts: 28
Default

"Method or Data Member Not found" Then it highlights ".ListIndex"
__________________
-Ryan L
"Noob in training"
Reply With Quote
  #6  
Old 11-09-2003, 07:47 PM
Illusionist's Avatar
Illusionist Illusionist is offline
Senior Contributor
 
Join Date: Oct 2003
Location: Chattanooga, TN USA
Posts: 1,069
Default

what language are you using?
.Net?
Reply With Quote
  #7  
Old 11-09-2003, 07:49 PM
zanth_quareni's Avatar
zanth_quareni zanth_quareni is offline
Senior Contributor
 
Join Date: Aug 2003
Location: Tomarria
Posts: 905
Default

If there is nothing selected, you will get an error. To check if there is something selected, do this:
Code:
If someList.ListIndex = -1 then 'there is nothing selected end if
__________________
...leben ohne sinn...
Reply With Quote
  #8  
Old 11-09-2003, 07:52 PM
knight knight is offline
Freshman
 
Join Date: Nov 2003
Posts: 28
Default

There was something selected and I'm using VB6.
__________________
-Ryan L
"Noob in training"
Reply With Quote
  #9  
Old 11-09-2003, 07:52 PM
Illusionist's Avatar
Illusionist Illusionist is offline
Senior Contributor
 
Join Date: Oct 2003
Location: Chattanooga, TN USA
Posts: 1,069
Default

If nothing is selected you get an invalid procedure call, not method or data member not found. He isn't using vb6.0
Reply With Quote
  #10  
Old 11-09-2003, 07:53 PM
reboot's Avatar
reboot reboot is offline
Keeper of foo

Retired Moderator
* Guru *
 
Join Date: Nov 2001
Location: Graceland
Posts: 15,612
Default

Post your revised code.
__________________
~ Quod non mortiferum, fortiorem me facit ~

Avatar by lebb
Reply With Quote
  #11  
Old 11-09-2003, 07:53 PM
Illusionist's Avatar
Illusionist Illusionist is offline
Senior Contributor
 
Join Date: Oct 2003
Location: Chattanooga, TN USA
Posts: 1,069
Default

Then what kind of listbox are you using?
Because ListIndex is a method of the Listbox control.
Reply With Quote
  #12  
Old 11-09-2003, 07:54 PM
zanth_quareni's Avatar
zanth_quareni zanth_quareni is offline
Senior Contributor
 
Join Date: Aug 2003
Location: Tomarria
Posts: 905
Default

Maybe your control name was lstABC and you said lstACB (of course not those names). Typos cause lots of probs in programming.
__________________
...leben ohne sinn...
Reply With Quote
  #13  
Old 11-09-2003, 07:55 PM
knight knight is offline
Freshman
 
Join Date: Nov 2003
Posts: 28
Default

Revised Code....
Code:
Private Sub Command3_Click()
lbo.RemoveItem lbo.ListIndex
End Sub
....And it's VB6.0
__________________
-Ryan L
"Noob in training"
Reply With Quote
  #14  
Old 11-09-2003, 07:55 PM
Illusionist's Avatar
Illusionist Illusionist is offline
Senior Contributor
 
Join Date: Oct 2003
Location: Chattanooga, TN USA
Posts: 1,069
Default

Then he would've got an object required error. Make sure you spelled ListIndex correctly.....
Reply With Quote
  #15  
Old 11-09-2003, 07:56 PM
reboot's Avatar
reboot reboot is offline
Keeper of foo

Retired Moderator
* Guru *
 
Join Date: Nov 2001
Location: Graceland
Posts: 15,612
Default

Are you using Option Explicit?
__________________
~ Quod non mortiferum, fortiorem me facit ~

Avatar by lebb
Reply With Quote
  #16  
Old 11-09-2003, 07:57 PM
knight knight is offline
Freshman
 
Join Date: Nov 2003
Posts: 28
Default

Quote:
Originally Posted by reboot
Are you using Option Explicit?


No, should I?
__________________
-Ryan L
"Noob in training"
Reply With Quote
  #17  
Old 11-09-2003, 07:58 PM
Illusionist's Avatar
Illusionist Illusionist is offline
Senior Contributor
 
Join Date: Oct 2003
Location: Chattanooga, TN USA
Posts: 1,069
Default

This works for me.....
Code:
Option Explicit ' works perfectly without this also.... Private Sub Command1_Click() lbo.RemoveItem lbo.ListIndex End Sub Private Sub Form_Load() lbo.AddItem "item1" lbo.AddItem "item1" lbo.AddItem "item1" End Sub
Reply With Quote
  #18  
Old 11-09-2003, 07:59 PM
knight knight is offline
Freshman
 
Join Date: Nov 2003
Posts: 28
Default

Tried what you said, but it still comes up with the same error.
__________________
-Ryan L
"Noob in training"
Reply With Quote
  #19  
Old 11-09-2003, 08:01 PM
Illusionist's Avatar
Illusionist Illusionist is offline
Senior Contributor
 
Join Date: Oct 2003
Location: Chattanooga, TN USA
Posts: 1,069
Default

What kind of listbox are you using then?
Reply With Quote
  #20  
Old 11-09-2003, 08:02 PM
Lar_19's Avatar
Lar_19 Lar_19 is offline
Senior Contributor

* Expert *
 
Join Date: May 2002
Location: Vancouver, USA
Posts: 999
Default

Quote:
Originally Posted by knight
Quote:
Originally Posted by reboot
Are you using Option Explicit?


No, should I?

The answer would be...ALWAYS!
__________________
1011 0000 1011
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

Similar Threads
Thread Thread Starter Forum Replies Last Post
How to show the selected item in a listview? Coen Interface and Graphics 1 09-26-2003 06:22 AM
Selected item in a listbox Rookie General 4 09-06-2003 09:30 AM
Selecting an item in a listbox without clicking vbmx General 5 07-07-2003 08:02 AM
VB Menus John General 8 02-05-2002 09:31 AM

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
 
 
-->