r/visualbasic • • Jul 09 '18

Making text-boxes appear and disappear while checkboxes are selected?

Interface

Hey, everyone. I was wondering if you guys could help me out or if you just have a solution. This is an interface for a school assignment. When the box/lawn/pavilion checkboxes are checked, a textbox becomes visible underneath. When the same checkbox is unchecked, the textbox's Visible property evaluate to false and disappears. The Visible property is set to false when the application is first run. You are allowed to have any number of the checkboxes checked at the same time as long as their accompanying textbox disappears when they are unchecked.

Does anyone have any ideas? I've been able to get everything else done but for whatever reason I can't figure this out. I've used both if...then statements and case statements but just can't crack it. If you need any other information feel free to message me. Thank you so much!

5 Upvotes

6 comments sorted by

3

u/SednaK9 Jul 09 '18

Use the changing of the checkbox as your trigger

2

u/chrwei Jul 09 '18

what exactly have you tried that isn't working?

2

u/JakDrako Jul 12 '18 edited Jul 12 '18

You could also use (abuse?) WinForm's databinding functionality:

Public Class Form1
    Private Sub Form1_Load(sender As Object, e As EventArgs) Handles Me.Load
        CheckBox1.DataBindings.Add("Checked", Me.TextBox1, "Visible", True, DataSourceUpdateMode.OnPropertyChanged)
        TextBox1.DataBindings.Add("Visible", Me.CheckBox1, "Checked", True, DataSourceUpdateMode.OnPropertyChanged)
    End Sub
End Class

EDIT: Actually, you can use only the "TextBox1..." line, the other one is redundant

1

u/CharlieMay VB.Net Intermediate Jul 09 '18

The visibility of a textbox is a boolean value. The checked value of a checkbox is a boolean value. Look at setting the visibility property of the textbox to the checked value of its corresponding checkbox. I would do this in an event that monitors if the checkbox changes its checked value.

1

u/Bonejob VB Guru Jul 09 '18

As I understand it you want to show or hide the textbox based upon the selected value of the checkbox above it. The first thing you need is an event to put code into. I would suggest either onchange or click of the corresponding checkbox.

in that event you need to write code that modifies the visible status of textbox.

so the way to make an object visiable or not is

object.visible = (true or false)

Figure out the event you want to use, then write code that makes the checkbox appear or disappear in that event.

Post your code so we can help.

0

u/kilo73 Jul 10 '18

If you only want one of them to be selected at a time, use radio buttons instead.