Combo Box Event

Two problems can arise when a confused user scrolls up or down with the mouse and then makes a selection with the Enter Key. First, the down arrow fires two events: Change and Click. Second, the Enter key moves focus to the next tab stop, while the mouse click doesn’t cause a loss of focus from the combo box. Therefore, if you place your action code in the Change event, an Up or Down arrow will fire it, which you don’t want. On the contrary, if you place your action code only in the Lost Focus event and the user clicks on a selection, focus won’t move from the combo box, and the user is left staring at the selected text in the combo box and wondering why no action occurred.
This solution filters out Click events generated with arrow keys, and forces the control to lose focus. In the Declarations section of the form, enter this code:

 ' Note: Use an Integer flag variable in ' VB3Dim bNoise as Boolean' True denotes a Noise Event which is to ' be ignored

Enter this code in the Form_Load event:

 bNoise = False        Enter this code in the combo box KeyDown event:Private Sub cbTest_KeyDown(KeyCode As _        Integer, Shift As Integer)        ' If the user is browsing with the         ' arrows, ignore the Click Events        If KeyCode = vbKeyDown Or KeyCode _                = vbKeyUp Then bNoise = TrueEnd Sub

Enter this code in the combo box Click event:

 Private Sub cbTest_Click()        If bNoise Then                ' Ignore Noise events                 ' (up or down arrow)                bNoise = False        Else                ' Force loss of focus                SendKeys "{TAB}", True        End IfEnd Sub

Write code that reacts to a new user selection in the combo box LostFocus event. Don’t send a Tab keystroke because focus has already shifted, and the combo box’s behavior is consistent regardless of how the user selects a new value.

Share the Post:
Share on facebook
Share on twitter
Share on linkedin

Overview

The Latest

homes in the real estate industry

Exploring the Latest Tech Trends Impacting the Real Estate Industry

The real estate industry is changing thanks to the newest technological advancements. These new developments — from blockchain and AI to virtual reality and 3D printing — are poised to change how we buy and sell homes. Real estate brokers, buyers, sellers, wholesale real estate professionals, fix and flippers, and beyond may

man on floor with data

DevX Quick Guide to Data Ingestion

One of the biggest trends of the 21st century is the massive surge in internet usage. With major innovations such as smart technology, social media, and online shopping sites, the internet has become an essential part of everyday life for a large portion of the population. Due to this internet

payment via phone

7 Ways Technology Has Changed Traditional Payments

In today’s digital world, technology has changed how we make payments. From contactless cards to mobile wallets, it’s now easier to pay for goods and services without carrying cash or using a checkbook. This article will look at seven of the most significant ways technology has transformed traditional payment methods.