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 wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Disabling a ListBox

Status
Not open for further replies.

vedicman

Programmer
Sep 5, 2003
128
US
I'm using the following code to write the value of the selected item of a list box to a specific cell. That works OK. After the value is written to the cell, I need to disable the list box and un-select the the selected item.
However, the listbox is still enabled, and I simply don't know how to unselect the selected item.

Any suggestions?

Private Sub lstProductID_Click()

Cells(Rows.Count, "A").End(xlUp).Select
Selection.Offset(1, 0) = Left(Sheets("Entry").lstProductID.Value, 3)
Cells(Rows.Count, "A").End(xlUp).Select
'lstProductID.Selected = "False"
lstProductID.Enabled = "false"
lstType.Enabled = "true"

End Sub
 
Code:
lstProductID.ListIndex = -1
lstProductID.Enabled = False


Regards,
Mike
 
Thanks Mike

I used your suggested code, but I'm still having the same problem. Any other ideas?

Franco
 
Franco,

Didn't realize your Listbox was on a sheet. In that case, I'm encountering the same problem as you; very quirky behavior. I believe it has to do with the control having the focus whenever it is clicked, but I'm not sure yet. Will continue to investigate.


Regards,
Mike
 


Hi,

Select another object?
Code:
Private Sub ListBox1_Click()
    With ListBox1
        .TopLeftCell.Value = .Value
        .TopLeftCell.Select
    End With
End Sub

Skip,

[glasses] [red]Be Advised![/red] A man who jumps from a bridge in Paris, is…
INSANE! [tongue]
 
Skip,

I thought of that, as well. In fact, I added selecting a worksheet cell to my Click event code and this seemed to work for me. I was ready to suggest this when I noticed that the OP is selecting a cell in his example code so I don't know how to account for his continued problem.


Regards,
Mike
 
I notice in the original code snippet that False and True are in quotes. Remove the quotation marks and try again.

lstProductID.Enabled = False '(not "false")


Greg

 
Greg,

See my initial response to the OP & follow-ups.


Regards,
Mike
 
Mike,
Sorry, I meant "" in Vedicman's original post.

I do have a question though, In your first post here, you have an integer as the first character of the listbox name. Is that allowable with controls on sheets?

Greg
 
Greg,

That's just the font talking [wink] I typed a lowercase L in the VBE then copied it over.


Regards,
Mike
 
An alternative to the use of 'Enabled' that does not work as expected on a worksheet (looks like the control is doubled, the second is OLEObjects(..).Object, property set only after selecting 'Edit' in design mode):

Code:
Private bListIsActive As Boolean

Private Sub CommandButton1_Click()
' activate list
Me.lstProductID.List() = Me.Range("A1:A8").Value
Me.lstProductID.ListIndex = -1
bListIsActive = True
End Sub

Private Sub lstProductID_Click()
If bListIsActive = True Then
    Cells(Rows.Count, "A").End(xlUp).Select
    Selection.Offset(1, 0) = Left(Sheets("Entry").lstProductID.Value, 3)
    Cells(Rows.Count, "A").End(xlUp).Select
    lstProductID.Clear ' just to hide selection
    bListIsActive = False
End If
End Sub

Private Sub lstProductID_MouseDown(ByVal Button As Integer, ByVal Shift As Integer, ByVal X As Single, ByVal Y As Single)
If bListIsActive = False Then
    Selection.Select ' to keep focus on worksheet
End If
End Sub

combo
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top