Items not showing in listbox - vb.net

I've got a simple list box on my VB form and I'm adding strings to it using the standard lstBox.items.add("string") command. However, the items aren't actually showing up in the list box. If I iterate through the items collection I can see that the strings are being added. They just aren't visible in the list box. If I add items to said collection before compilation, using the IDE, they show up fine and I can delete them in the normal way. I have tried deleting and re-adding it but that hasn't helped.
Quite frankly I am stumped, because I have used listboxes hundreds of times and I can't get this to work. So any help would be appreciated.
The exact code to add items to the list is:
MainForm.lstPendingJobs.Items.Add(MainForm.currentJob)
I have tried moving this subroutine into the mainform class and that didn't help either.

Could it have been that you had accidentally altered the DrawMode property from Normal to OwnerDrawFixed or OwnerDrawVariable?
This would account for the non display of the items even though they are in the list box

item in your case is an object. You need to get a value out of it.
Try msgbox(item.value)

Related

How can I make a dropdown list to delete not compatible fields?

I want to make a form that deletes the fields that are not possible as It is filled. I want to make a dropdown list and when ever something is selected deletes other fields.
I'm not getting to run the dropdown part.
I'm new at this but it should be something easy to make. I have a dropdown list in word with different values(0,1,2,3,4) for the different options.
I'm trying to run the code from this link
ActiveDocument.FormFields("DropDown1").DropDown.Value = 1
It gives me:
Runtime error '5941': The requested member of the collection does not exist.
Possible this is a very basic mistake but I'm spending a lot of time on this and I find it very difficult to find resources for VBA for word. Any help would be very appreciated.

How can i create a list to select from for a property on my user control?

I have a property on my user control called 'DataGridViewColumnType' and wondered if it was possible to make it a drop down and a list of column types to choose from? Even if it was just a list of strings would be good enough.
I have been playing with the attribute
<Editor("System.Windows.Forms.Design.DataGridColumnCollectionEditor, System.Design", GetType(UITypeEditor))>
But not having much luck and not sure it'd actually do what I want even if if I could get it to work. It just opens a column collection editor but the add button doesn't work and i haven't been able to get it to work so couldn't get any further.
So i thought if I can just create the list myself then somehow turn my property into a drop down that displays my list that would be fine. I just haven't done this before and can't seem to find much on how to achieve it.

Context menu to delete items from a ComboBox

Currently, I've designed my own combobox from a ListBox/Button/TextBox to accomplish this, but I'm finding this to be way to much work to try and get a hacked together ComboBox to look like an actual ComboBox control.
This does however give me the desired effect however. Sort of ...
But my question is, is there not a simpler way to do this? Is there a way to simply right click on an item in a ComboBox, and get a context menu that says "Delete" for that specific entry?
Here is an example of the desired effect with my hacked together ComboBox:
I've tried simply linking a ContextMenu to a ComboBox, but that only allows for right click on the actual ComboBox itself, not the drop down, which renders this useless to me.
Any help or advice would be greatly appreciated.

Arrow keys don't work after programmatically setting the selected item in a listview

I have a listview with some things in it, and I have a sub that will refresh the listview by deleting everything in it and re-populating it.
However, when the user selects an item and the list refreshes, I wanted to have that same item select itself once more. I accomplished that by doing:
ListView.Items(4).Selected = True
ListView.Select()
which selects the 5th item in the list view (counting 0). However, when the user presses the up or down keys, the selected item jumps back up to the top item in the list, and I can't find a way around this.
The only search that has come up with anything is here:
Arrow keys don't work after programmatically setting ListView.SelectedItem
But I do not understand the responses, I need a dumbed down version or a simpler solution if possible, thank you.
Try using the Focused property on an Item. Seems like I may have run into this before.
ListView.Items(4).Focused = True
You may also need to set that same property to False for the first item in the list.

limit selections in a listbox in vb.net

I am creating a web control in vb.net that contains a list box. I know that I am able to choose a selection mode of Single or Multiple, but I am interested in limiting a Multiple selection to a predetermined size. For example preventing a user from selecting more than 3 items.
I have tried adding a Validator to the list box, which might be a way forward, but was wondering if there was a way of changing the selection mode to something a bit different than just the two specified ones.
Any ideas or suggestions would be greatly appreciated
Edit: Unfortunately due to project limitations I am unable to use Javascript on this problem. very annoying I know!
You could try handling one of the SelectedIndexChange events. With multiple selection, each time this event fires you can check how many items have already been selected. If it is more than you want, have the handler deselect the one that was just selected. You could also put up a little red label under the listbox saying "Sorry, no more than [n] selections allowed."
EDIT:
Just noticed you said WEB. Same theory applies, but it would have to be done using Javascript.
On the SelectedIndexChanged event, write a short piece of code that will check the number of selected items and if it is greater than your desired amount, unselect the new selection (or unselect the oldest one, or however you wish this to operate).