Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Value property not updating after list box selection change

Status
Not open for further replies.

jjmclell

Technical User
Aug 10, 2007
34
CA
Hi there,

I have a list box with a bunch of items in it. The user can select an item and hit a delete button to remove it which then causes some other things to happen. Basically, as part of that event, I need to select the next item in the list and return its value, as shown below:

Code:
[B]Form1!listOfItems.Selected(next) = True[/B]
[I]Do something with[/I] [B]Form1!listOfItems.Value[/B]

As far as I can tell from the help files, calling for the value property of a list box is supposed to return the value of the selected item; however, in this case it's returning the value of the previously selected item - the one that the user originally selected. The value property is not updating to reflect the change in selection in the list box. Any ideas?

jjmclell
 
I'm guessing... you might be looking for ListBox.ItemsSelected rather than Value.

Hope this helps.

"If it's stupid but works, it isn't stupid."
-Murphy's Military Laws
 
ItemsSelected is the collection of selected items in a multi-select list box. I have the multi-select property set to none so it doesn't apply. Currently, the way things work, when I select a different item in the list box, the previously selected item becomes unselected as I've verified in the immediate window:

Code:
?Form1!listOfItems.Selected(previous)
0
 
Ok, it seems I've figured it out. Instead of using

Code:
Form1.listofItems.Selected(next) [I] and then trying to return [/i] Form1.listofItems.value

I used:

Code:
Form1.listofItems.Itemdata(next)

I swear I've found a bug though b/c the value property of a list box is supposed to return the bound column value of the selected item; yet when I programmatically changed the selection, the value property wouldn't update.
 
Probably not a bug, but explained by the difference between .Text and .Value for a Text Box. The TextBox.Value is not available until the box loses focus. TextBox.Text is only available when the control has the focus.

I haven't done any testing, but this might be the same kind of thing for the .Value of the ListBox. What I'm thinking is that by setting the selected or itemdata or other such properties, the focus is returning to the ListBox and therefore .Value is not what you expect.

Just a thought though.

"If it's stupid but works, it isn't stupid."
-Murphy's Military Laws
 
moves to the next and returns the correct value:

Me.lst0.Value = Me.lst0.Column(0, Me.lst0.ListIndex + 1)
Debug.Print Me.lst0.Value

 
Cool, thanks for the help everyone!!

jjmclell
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top