Visual Basic Classic
--
Questions
--
Followers
Top Experts
I have a bound combobox which, when I press backspace (as users may do instead of pressing the delete key), the value of the combobox automatically changes to the first value in the dropdown list of values. The wacky thing is, the .Text value matches the first dropdown value, but the combobox ListIndex value is -1 (denoted no selected value). Am I missing something? It looks as if the Backspace is being overridden somehow.
How can I ensure that when the user presses either Delete or Backspace (yielding a *visually* empty field since the original value text is all highlighted upon opening the form), that the combobox simply clears out the value from the control?
Later, when the user closes the form, I am checking if the combobox value is empty so that I can prompt the user for a confirmation (it's a business requirement to do this) that it's OK the field is empty...but unfortunately the field is never "getting" empty when using the Backspace key. Using the Delete key does work though. Arrrrgh!
Thanks for your help.
Zero AI Policy
We believe in human intelligence. Our moderation policy strictly prohibits the use of LLM content in our Q&A threads.
With dropdownlist the delete and backspace have no affect. Only in the dropdown combo style. So change to dropdown combo and delete and backspace would clear the combobox text area.
S
Private Sub Combo1_KeyDown(KeyCode As Integer, Shift As Integer)
If KeyCode = vbKeyDelete Or KeyCode = vbKeyBack Then
Combo1.ListIndex = -1
End If
End Sub
S






EARN REWARDS FOR ASKING, ANSWERING, AND MORE.
Earn free swag for participating on the platform.
They are normally on the right hand side of the ide. If you dont have properties window on the right hand side, then click view on the menubar and select properties window.
<<Infragistics UltraSuite "PVCombobox">> I'm not familiar with that, is that a third party control?
S

Get a FREE t-shirt when you ask your first question.
We believe in human intelligence. Our moderation policy strictly prohibits the use of LLM content in our Q&A threads.
(combo1 would be replaced with the name of your control)
Private Sub Combo1_KeyPress(KeyAscii As Integer)
If KeyAscii = vbKeyBack Then
' if user has entire contents selected
If Combo1.SelLength = Len(Combo1.Text) Then
' entire text is selected - manually delete the text
Combo1.Text = "" ' or other appropriate action
' eat the keystroke
KeyAscii = 0
End If
End If
End Sub
magnare
S






EARN REWARDS FOR ASKING, ANSWERING, AND MORE.
Earn free swag for participating on the platform.
Visual Basic Classic
--
Questions
--
Followers
Top Experts
Visual Basic is Microsoft’s event-driven programming language and integrated development environment (IDE) for its Component Object Model (COM) programming model. It is relatively easy to learn and use because of its graphical development features and BASIC heritage. It has been replaced with VB.NET, and is very similar to VBA (Visual Basic for Applications), the programming language for the Microsoft Office product line.