Wednesday, December 7

Disable editing in combobox control in VB.Net

This is a very simple tutorial yet it's very helpful. We use combobox to dispaly an editable list of text/string but what if we do not want or allow our user to edit the items in a combobox? what we want is to select from list of choices. This codes will disallowing our user to modify or edit the text/string in our combobox control.

First drop a combobox control in the form and name it. Go to the code and declare a boolean variable and set it to false:




Public Class Form1
Dim editingInCombobox As Boolean = False


then create keypress event in the combobox control (creating event in vbnet code window).



Once you done, add the following line of codes in the keypress block:


If Not editingInCombobox Then e.Handled = True

Beep()



editingInCombobox = is the boolean variable we declared
Beep ( ) = Sounds a tone through the computer's speaker.

That's it, I hope you like it.



15 That ye may be blameless and harmless, the sons of God, without rebuke, in the midst of a crooked and perverse nation, among whom ye shine as lights in the world;


Philipians 2:15 KJV


Praise to LORD JESUS CHRIST


2 comments:

  1. I have new, simply type, ComboBox1.DropDownStyle = ComboBoxStyle.DropDownList

    ReplyDelete
  2. Some vb codes new in http://joysources.info

    ReplyDelete