Source language: Translate to:

Using the ListBox

NeoBook tips, tricks, code samples and more...

Moderator: Neosoft Support

Using the ListBox

Postby Jim Brammer » Thu Feb 07, 2002 4:27 pm


Anyone come up with a way to get the name of text entered and delete an item easily?

Example: Items in ListBox Apple,Box,Car

Item Text is selected so that an alert can pop up and say, Are you sure you want to delete the "Apple", etc.

If the person selects yes, the ListBoxDeleteItem wants to know what item number to delete. Now, since I selected "Item Text" instead of "Item Number", I don't know what line to tell ListBoxDeleteItem.




There's two ways to use the ListBox.

List Item Numbers
List Item Text

The ListBox uses mostly numbers to do it's work. If you need to use Item Text then you need to Find the Text of the Item that was selected. That's what the ListBoxFindItem command is for. This command will return the Number of the Item that matches the selected Text. Use this Number to Delete the Item Number from the List...

( ListBox1 > Item Text > [ListBoxSelectedText] )

MessageBox "Delete?" "Are you sure you want to Delete '[ListBoxSelectedText]'?" "Delete|Cancel" "[AskDelete]"

If "[AskDelete]" "=" "1"
ListBoxFindItem "ListBox1" "[ListBoxSelectedText]" "[ListItemNumber]"
ListBoxDeleteItem "ListBox1" "[ListItemNumber]"

The other way, which I use more often than Item Text, is to start off with Item Number. When an Item is selected from the List you already have the Number. If you need to ask "Are you sure you want to Delete '[SelectedItemText]'?" Then you first need to Get the Text for the selected Item Number. Same thing in reverse.

( ListBox1 > Item Number > [ListBoxSelectedNum] )

ListBoxGetItem "ListBox1" "[ListBoxSelectedNum]" "[ListItemText]"
MessageBox "Delete?" "Are you sure you want to Delete '[ListItemText]'?" "Delete|Cancel" "[AskDelete]"

If "[AskDelete]" "=" "1"
ListBoxDeleteItem "ListBox1" "[ListBoxSelectedNum]"

Name your variables descriptively so that you can read them and understand what they mean and what they do. Short, indescript variables make it a lot harder to understand what you're sending to and from ListBoxes (or anything else for that matter!).
Jim Brammer

Return to NeoBook Knowledgebase

Who is online

Users browsing this forum: No registered users and 0 guests