Hi all,

I am working on a simple form for work, which has multiple questions (labels) and text boxes and combo boxes (to answer the questions).

My issue is that i do not wish to show all the questions right from the start. Some questions will remain non-visible, until a previous question is answered by selecting either "Yes" or "No" from a combo box.

My problem is that, when i select "Yes" i have asked that the next "Label" be made visible which it does and that the next "Textbox or Combobox" be made visible, which it also does. BUT where as it places the label right underneath the previous question, it places the "Textbox or Combobox" at the bottom of the page, which i do not want.

I have already tried locking the location of the "Textbox or Combobox" but with no joy.
I also have Autoscroll enable on the form these controls are in.

Here is the code i am using:

Private Sub comboboxQuestion11_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles comboboxQuestion11.SelectedIndexChanged

        'If the product does need to be set to a specific tone, then this label is made visible'
        If comboboxQuestion11.Text = "Yes" Then
            lblQuestion12.Visible = True
        Else : lblQuestion12.Visible = False
        End If

        'If the product does need to be set to a specific tone, then this textbox is made visible'
        If comboboxQuestion11.Text = "Yes" Then
            txtboxQuestion12.Visible = True
        Else : txtboxQuestion12.Visible = False
        End If

    End Sub

If anyone could make some suggestions on how to stop this, that would be geat.

Thankyou

Dani AI

Generated

This looks like a layout/parenting issue rather than a logic problem. The code posted simply flips Visible, which only shows the control where it was placed at design time. As suggested, double-check whether the textbox was accidentally placed behind/away from the label or in a different container. The advice below assumes a Windows Forms app (the Handles ... SelectedIndexChanged pattern), but a short note for ASP.NET is included at the end.

Quick checks

  • In the designer, verify txtboxQuestion12.Location (X,Y) and txtboxQuestion12.Parent. If its Y is large or Parent is a different panel/form, it will appear far down.
  • Check Anchor/Dock properties — avoid anchoring to Bottom/Right if you want it to stay under the label.
  • Check z-order (BringToFront/SendToBack) if it might be hidden behind another control.
  • If AutoScroll = True, remember scrollbars appear when controls lie outside the visible client area.

Practical fixes

  • Move the textbox next to the label in the designer, or position it at runtime relative to the label:
    
    ' position directly under a label and make visible
    txtboxQuestion12.Location = New Point(lblQuestion12.Left, lblQuestion12.Bottom + 6)
    txtboxQuestion12.Visible = True

' ensure the container scrolls to it if needed
Me.ScrollControlIntoView(txtboxQuestion12)


- For forms with many dynamic show/hide fields consider using a FlowLayoutPanel or TableLayoutPanel so controls flow/stack automatically (see FlowLayoutPanel docs: https://learn.microsoft.com/en-us/dotnet/api/system.windows.forms.flowlayoutpanel?view=windowsdesktop-7.0). Use `ScrollControlIntoView` when AutoScroll is enabled (https://learn.microsoft.com/en-us/dotnet/api/system.windows.forms.control.scrollcontrolintoview?view=windowsdesktop-7.0).

If this really is an ASP.NET page, layout is controlled by HTML/CSS — hide/show with CSS (`display:none` / `block`) or client-side script and keep the markup order so new fields appear in the expected spot.

Recommended Answers

All 4 Replies

post a screenshot

Here is the print screen, i have added notes showing where the boxes appeared wrongly

thankyou

why u put box behind another control?
you want to show first textbox after user select yes on first combo box.right?
set first textbox visible = false when form load then after user select yes u can set visible to true. so u don't have to put box behind combox.
See this example :

Private Sub Tes2_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        TextBox1.Visible = False
        With ComboBox1.Items
            .Add("yes")
            .Add("no")
        End With
    End Sub

    Private Sub ComboBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ComboBox1.SelectedIndexChanged
        If ComboBox1.SelectedItem = "yes" Then
            TextBox1.Visible = True
        Else
            TextBox1.Visible = False
        End If
    End Sub

Yes that is what i did, but when i then select "Yes" from the combo box. Which makes the next box visible. It makes it visible but in completely the wrong place. thats the problem.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.