Enabling and Disabling text boxes
-
I am trying to write a code for enabling and disabling a textboxes for output and for input during certain times in the program. One of my textboxes is PartNumber.text. At the beginning of the program I want to disable this box; however, if they want to add another Part this box will become clear so they can input a number so I want it to be enabled. I am confused on how to write it. Thank you, ibok23
-
I am trying to write a code for enabling and disabling a textboxes for output and for input during certain times in the program. One of my textboxes is PartNumber.text. At the beginning of the program I want to disable this box; however, if they want to add another Part this box will become clear so they can input a number so I want it to be enabled. I am confused on how to write it. Thank you, ibok23
You use the Enabled property of the TextBox control. When to enable it and disable it depends on your design. If I remember right, you were using menus to do Add, Delete, ... If the Click handler of the Add MenuItem, you would use something like this:
Private Sub mnuAdd\_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuAdd.Click **txtPartNumberTextBox.Enabled = True** ... the rest of your code to enable controls and buttons goes here ... End Sub
The user would have to click some button you have on your form to tell your app that all the data is entered and to process it to add it to a database. This button has a Click handler. This is where you would disable the textboxes and buttons you need to:
Private Sub btnAddData\_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAddData.Click **txtPartNumberTextBox.Enabled = False** ... the rest of your code to disable controls and buttons goes here ... ... also the code to process the data to add goes here... End Sub
RageInTheMachine9532