Performing action on each selected item in Listbox VB.net - vb.net

I am populating a listbox with a large list. The user then has the option of choosing multiple items from this list. I then want to perfrom a few actions on only the selected items.
I cant figure out how to only perform the actions on only the highlighted selections.
'I have tried all combinations of
For each Listbx.SelectedItems.ToString in ListBx.Items.ToString
For each Listbx.SelectedItem in Listbx.Items
'etc, etc
''Performing actions here but it is still doing it with all entries
Next

For Each selecteditem As [Object] In Listbx.SelectedItems
//Your code on each item
Next

Related

Excel VBA mulitiple checkboxes

is it possible to create listbox with multiple checkboxes in one row (Excel VBA)?
Thanks
Kamil
I'm not sure I understood your question fully, but I'll elaborate on ListBoxes as much as I can.
First things first: Checkboxes and ListBoxes are different objects in Excel Userforms. The first is the little box that returns a "true/false". The second is a list of items which can be chosen. Clicking in a Checkbox will make the tick mark appear/disappear (or fade if tristate is enabled), while clicking a Listbox row will turn the listbox row "blue"/"white" (or whatever color is being used for the selected rows). In both elements, clicking is a way to toggle between True and False.
While a checkbox only allows for a single information to be marked as True or False, a Listbox allows you to select entries out of a list. That list may be inserted through code (.AddItem method) or passed from a range (.RowSource property)
ListBox objects allow for multiple columns of data to be attributed to one row element, but each row is an entire element (which means you cannot pick the element on row 3, column 2 - only all of row 3). The number of columns is established using the ColumnCount property.
By changing the value of the MultiSelect property, you'll allow the user to select multiple or single row elements simultaneously on your Listbox. Using the Selected( RowIndex ) property, you can check whether or not an item is currently selected (returns True/False). Remember that row indexes start at 0.
Finally, if you're using the MultiSelect property set to fmMultiSelectSingle and have a single column (as far as I know), the Text property can be used to return the selected item's value.
An easy example of a listbox is in Excel can be found at File > Options > Customize Ribbon (or something like that). There are two listboxes, one (on the left) with the visible items and another with the available items. A pair of command buttons is used to move items between boxes. That's a simple application you can likely find already setup online.
Am I on track to answer your question?

Comparing two list boxes Vb.net

Listbox 1 contains names of hairdressers and Listbox 2 contains services provided by all of them then in Listbox 3 both the selected hairdresser(only 1 allowed) and and selected services are contained. There is a remove button which removes items from Listbox 3. I want a code for the button that if a hairdresser is removed all services also get removed otherwise only services are removed.
For Each str As String In Hairdresser.lstHairdresser.Items
If Not lstHairdresserAndServices.Items.Contains(str) Then
lstHairdresserAndServices.Items.Clear()
Else
'more code here but above statement never gets true
End If
Next
If the hairdresser is always the first item in the 3rd listbox, all you have to do is check if the selectedindex equals 0. If so, clear the listbox. Otherwise just remove the selected item.
Alternatively, you could search the the 1st listbox for the selected string. If found clear the listbox otherwise remove the selected item.
It is also possible to mark the listbox items when you add then to the listbox. Set the tag property to something like "hairdresser" or "service" and when the remove button is clicked all you have to do is check the tag property.
Finally I would recommend a different approach: Instead of adding the items to the listbox, fill a data structure with the hairdresser's name and services, display this structure in the listbox and when the remove button is clicked compare the selected item to the structure to find out what was selected.

Extjs4:Multiselect Option

In my form,i have a list of employees in a combo box and i need to map some employees to particular department.I need to change the combo-box to List box.Scenario is as follows,
1. List A contains all employees.
2. If i click 'Add' button the selected employees must move to list B
and list A must contain remaining employees
.
I searched for List box but i couldn't find in extjs4.
Is there any example or link for multiselect listbox in ext-js4?
Thanks
There is no built-in ListBox widget in ExtJs4. However, Ext.view.View may become an listbox after some manipulations.
Here is an example of such a tuned View. Demos may be found here, here and here (this one looks like just what you need).
You can create two such listboxes and the "add" button. Then assign handler to button which would remove selected item from the first listbox's store and add it to the second's store.

Removing items from ListBox A based on the items in ListBox B

I am trying to remove items from a listbox based on the items on another listbox, this seems simple but apparently I can't get my code to work, please advice. Thanks.
Dim listRemove As New List(Of ListItem)
For Each item As ListItem In QualOutletToBox.Items
listRemove.Add(item) ' Collect items from ListBox A
Next
For Each item In listRemove
QualOutletFromBox.Items.Remove(item) ' Remove items from ListBox B based on ListBox A
Next
Regarding the follow-on question, yes, there is a much less resource intensive method, a single loop:
For Each item As ListItem In QualOutletToBox.Items
QualOutletFromBox.Items.Remove(item) ' Remove items from ListBox B based on ListBox A
Next

change the list of combobox A based on the item chosen from combobox B

I am new to vb.net and I am using visual studio 2010. I have two comboboxes on a form, each combobox is set to DropDownList so that a list of items can show in the combobox, but no text is allowed to be entered.
For combobox A, if user chooses item 1, the list of combobox B should be updated accordingly. I think this is quite common on a lot of applications. But I do not know to implement it. I even do not know the keyword to search for the relevant property or event handler.
Thanks a lot!
Take a look at SelectedValueChanged. You can subscrive to this event on your first combobox, then when the event is raised, you can combo2.Items.Clear () the 2nd collection, then add your items.