nothing selected in listbox, but listindex <> -1

S

steve

I have a multicolumn listbox on a userform. When the user selects an item,
text boxes are then filled in from the selected item.

I assumed if no item was highlighted in the listbox, then the
listbox.listindex would be -1. There are situations, however, where nothing
is selected but the listbox has a listindex of whatever the most recently
selected item was.

any ideas of what's going on here? Is there some way I can check to make
sure something is "highlighted" in the listbox?

thanks,
Steve
 
S

steve

I've narrowed it down to this: The list box becomes record becomes
"unselected" when I press the Update button. The update button takes values
from a text box, tbMeshQuantity, and updates column (1) of the selected
record. When this button is pressed, the record is updated, but then
unselected. The listbox thinks it's still selected though. Code for the
Update button below.

Private Sub cbUpdate_Click()
If Me.lbMeshShoppingCart.ListIndex = -1 Then
MsgBox "select an item first"
Exit Sub
End If

With Me.lbMeshShoppingCart
.ColumnCount = 2
.ColumnWidths = "75;75"
.List(.ListIndex, 1) = Me.tbMeshQuantity.Value
End With
End Sub
 
S

steve

Ok, I think I got it. Each time I was pressing Update, I was setting the
..columncount property and .columnwidths property. This was taking the focus
off of the selected record. I moved these items to the Form Initialize
event, and everything seems to be working.

Please let me know if someone has something else to add.

-steve
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top