Link to home
Create AccountLog in
Visual Basic Classic

Visual Basic Classic

--

Questions

--

Followers

Top Experts

Avatar of magnare
magnare

ComboBox Mystery: The Case of the Rejected Backspace Keypress
Hi:

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.


Avatar of ShauliShauli

Are you using Dropdown Combo or dropdown list as your Style property?
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

Or, if you must have it in dropdown list, then put this code in the KeyDown event of the combo. Please modify the combo name:

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

Avatar of magnaremagnare

ASKER

Thanks for the reply - I'm using an Infragistics UltraSuite "PVCombobox".   I need to bind the combobox to an ADO datacontrol that is on the form & so I didn't use the "built-in" combobox that comes with VB6.  To answer your question, I don't see where the properties you mention are available for me to check them.

Reward 1Reward 2Reward 3Reward 4Reward 5Reward 6

EARN REWARDS FOR ASKING, ANSWERING, AND MORE.

Earn free swag for participating on the platform.


Avatar of magnaremagnare

ASKER

Actually, the ListIndex value *is* -1 by the time I inspect it in the KeyPress event, although the .Text value corresponds to the first dropdown list value.  If I close the form, that first value is what is getting stored, which is not correct of course.


<<To answer your question, I don't see where the properties you mention are available for me to check them.>>
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


Avatar of magnaremagnare

ASKER

Sorry I wasn't more clear - I have checked the property list in the IDE & don't see a property containing the values you mentioned.  It is a 3rd party control (Infragistics UltraSuite "PVCombobox").  I didn't see a way to use a "normal" combobox and bind it to an ADO data control so I looked to this control - everything else about is pretty nice with respect to formatting, but the handling of the Backspace key is a real annoyance.  

Free T-shirt

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.


ASKER CERTIFIED SOLUTION
Avatar of ShauliShauli

Link to home
membership
Log in or create a free account to see answer.
Signing up is free and takes 30 seconds. No credit card required.
Create Account

You might try to catch the user pressing backspace and do your own thing:

(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

Avatar of magnaremagnare

ASKER

Thanks Shauli for sticking with me on this one...I switched to an intrinsic combobox & it works fine with both the Backspace & Delete keys to clear the field value.  Thankfully, I had very simple needs for this particular combobox.  It was kind of a "duh" moment on my part for not thinking of loading the combobox as you've shown, but nonetheless I sincerely appreciate your help.

magnare

Glad it works for you :)

S

Reward 1Reward 2Reward 3Reward 4Reward 5Reward 6

EARN REWARDS FOR ASKING, ANSWERING, AND MORE.

Earn free swag for participating on the platform.

Visual Basic Classic

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.