Unselecting 1 Listbox Item

ndavenport

Member
Joined
Sep 2, 2009
Messages
8
Programming Experience
Beginner
I have a listbox that contains several items (the amount of items changes depending on who is using the application). The listbox is setup so the user can select more then one item. I am attempting to submit the user selection(s) to the database. The problem I'm having is that when I loop through the array to find out what is selected, I'm only getting the first item selected (because I cannot deselect it).


For Counter = 0 To lstEmailFreq.SelectedItems.Count - 1
PreferenceKey = lstEmailFreq.SelectedValue 'Get the PreferenecKey for processing

'Next insert new records
Me.Tbl_FrequencyConfigurationsTableAdapter.Insert1(ClientKey, EmailChannel, PreferenceKey, EmailTimeFrame, EmailDuration, EmailCounter, 1)

Next

What I think I need is someway to deselect the first item from the listbox so the next loop through will grab the second item and so forth. I hope I'm being clear on this explination. Thanks in advance for any help.
 
VB.NET:
Dim one = lstEmailFreq.SelectedItems(counter)
 
Thanks for the feedback. Unfotunately I'm not quite sure how to use that. It is a datarowview and I can see the data I want when debugging. However, I'm not sure how to either get the data I want out of it (ItemArray(5) has the value that I'm ultimately looking for) or use the return to select or deselect a row. It's probably very basic I know but I'm new to this type of thing still. Thanks!
 
Dim one As DataRowView, I don't think you have type inference with VB 2005.
VB.NET:
Dim value As Object = one(lstEmailFreq.ValueMember)
 
That worked! I'm not quite sure how or why it worked, but it did. I'll have to go back and take a closer look. Thanks so much for all the help! :)
 
Back
Top