[RESOLVED] Scrollbar not appearing on panel
I’m trying to display a large list of data with a panel with dynamic textboxes but there is no scrollbar appearing on the panel. The autoscroll property of the panel is set to True in the designer. The initial size of the panel is 960, 620 and the size of the form is 1000, 800.
Code:
100 + (NumRows * iRowHeight)
calculates as 65,535. Can someone tell how to get the scrollbar to appear? Or is a panel the wrong way to go? I do not want a datagridview or listview.
Code:
iRowHeight = 36
NumRows = dt.Rows.Count
ReportPanel.Height = 100 + (NumRows * iRowHeight)
Dim txtbx() As TextBox
txtbx = Nothing
ReDim txtbx(NumRows)
index1 = 1
For Each row As DataRow In dt.Rows
txtbx(index1) = New TextBox
txtbx(index1).Visible = True
txtbx(index1).Top = 5 + (iRowHeight * index1)
txtbx(index1).Width = 225
txtbx(index1).Height = 20
txtbx(index1).Left = 140
txtbx(index1).Text = IIf(IsDBNull(row.Item("warehouse")), String.Empty, row.Item("warehouse"))
AddHandler txtbx(index1).Click, AddressOf MyMessage
Me.ReportPanel.Controls.Add(txtbx(index1))
index1 = index1 + 1
Next
Re: Scrollbar not appearing on panel
You ought to look at the FlowLayoutPanel, as that would likely be a better way to go with dynamic controls.
Re: Scrollbar not appearing on panel
Thanks.
I tried this and I'm getting some puzzling results. Using the above code except adding the textbox to a flowlayout panel it scrolls the textboxes out across the panel. (Or maybe down and then across.) And no scroll bar appears. Autoscroll is set to true in the designer. So I made the panel narrower so as to be wide enough for just 1 textbox and when this thing is being created the whole screen blacks out for a few seconds whenever I move the cursor. When it stopped there was only 1 textbox per row and a scrollbar but the scrollbar didn't work.
(The final result is to have many columns.)
Re: Scrollbar not appearing on panel
In your original code, you're increasing the size of the panel to fit all of your textboxes. Therefore there are never any controls outside of the panels visible viewport. Try your original code and set the form's autoscroll property to true...
Re: Scrollbar not appearing on panel
Okay, it's much better after removing the height-setting statement. But how do I add more textboxes going across? I tried creating another one in code, increasing the .Left amount and that didn't work.
Re: Scrollbar not appearing on panel
Forgot the .Add statement. Thanks!
Re: Scrollbar not appearing on panel
The flowlayout panel was largely designed for this, and it has lots of different properties. There is one that adds horizontally vs vertically, and it sounds like you had that set. Of course, there's nothing particularly special about the flowlayout panel. It's doing what you are doing, so if you get it working without the flowlayout panel then there may be no real advantage.
Re: Scrollbar not appearing on panel
How would I get it to work without the flowlayout panel? With a regular panel?
Re: Scrollbar not appearing on panel
How do you get a scroll bar to appear on a regular panel?
Re: Scrollbar not appearing on panel
I told you how...
I thought you had it working???
Re: Scrollbar not appearing on panel
I never got a scrollbar on the panel. The flowlayout panel has a scrollbar but the textboxes wrap around/don't jump to the next line. Obviously I need to fill out the width with the rest of the text boxes but I have misgivings that I will get it to look the way I want. Also, I think the flowlayout panel is executing slower than the panel. So for that reason alone I would want to go with the panel.
Re: Scrollbar not appearing on panel
With autoscroll on, the panel will show scrollbars when there are controls positioned outside of the visible bounds of the panel.
For example:
Panel1 size = 200, 100
Textbox1 location = 20,150
Textbox1 is beyond the bottom of Panel1, so a vertical scrollbar will appear...
Re: Scrollbar not appearing on panel
All right I will give this a try.
Re: Scrollbar not appearing on panel
This looks good! The problem was in setting the height of the panel to be the size of the full list instead of the visible size same as with the flowlayout panel.
And panel executes faster than flowlayoutpanel.
So it looks like I'm good for now. Knock on wood. Thanks both of you.
Re: Scrollbar not appearing on panel
You can mark this as resolved.
Re: Scrollbar not appearing on panel
The panel is also easier for positioning controls
Re: Scrollbar not appearing on panel
See the menu at the top right of your original post - Thread Tools. It has an option to Mark Thread Resolved