Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,814
Default nothing selected in listbox, but listindex < -1

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
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,814
Default nothing selected in listbox, but listindex < -1

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


"steve" wrote:

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

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,814
Default nothing selected in listbox, but listindex < -1

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

"steve" wrote:

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


"steve" wrote:

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

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Listindex problems in multicolumn listbox [email protected] Excel Programming 0 August 18th 06 11:02 PM
ListBox and ListIndex mtm4300 via OfficeKB.com Excel Programming 2 April 5th 06 05:56 PM
Select Listindex from column A on selected row KD[_5_] Excel Programming 1 February 10th 06 10:49 PM
listbox listindex problem jacob Excel Programming 2 August 25th 04 08:46 AM
listbox.value not equal to listbox.list(listbox.listindex,0) ARB Excel Programming 0 October 22nd 03 12:46 AM


All times are GMT +1. The time now is 03:49 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"