Zack
Zack

Reputation: 117

Using combo boxes in Visual Basic

What is the best way to deal with a combo box event? In other words, what is the best event handler to use for the case that the user makes a selection from the combo box? I am using a textchanged event, but it seems a bit sloppy. Is there a better way? By the way, my program that I am using it for is a unit converter that converts length.

Upvotes: 1

Views: 469

Answers (1)

Malcolm Salvador
Malcolm Salvador

Reputation: 1566

The textchanged event fires whenever the text inside the combobox changes. every character added to the combobox triggers it, which makes it sloppy.

To avoid performance issues, use either Lostfocus (which fires if the control isn't selected anymore) or the SelectedValue /Selectedindex changed events.

To answer your other question, manipulate the keypress event.

Go to the combobox's keypress event, and type this:

       e.handled = true

this will reject any input from user.

Upvotes: 2

Related Questions