Confused Old Programmer - building a form internally.

AlJones

New member
Joined
Jul 12, 2022
Messages
2
Location
Terlingua, Texas
Programming Experience
10+
I'm retired and older than Methuselah so please be nice and bear with me. The last 'production programming' I've done was in VB.Net 2015 and am trying to upgrade my abilities in VB Community 2022.
Given the following code segment:

VB.NET:
        Dim lrow As Integer = 60
        Dim lcol As Integer = 25
        ReDim lblqus(currentrow.Length)
        For i = 0 To currentrow.Length - 1
            lblqus(i) = New Label With {
                .Name = "lblqus" & i + 1,
                .Size = New Size(74, 18),
                .Visible = True,
                .BorderStyle = BorderStyle.FixedSingle,
                .Font = New Font("Microsoft Sans Serif", 10, FontStyle.Regular),
                .BackColor = Color.MistyRose,
                .Location = New Point(lcol, lrow),
                .Text = currentrow(i)
            }
            'set the location
            Controls.Add(lblqus(i))
            lrow += 25
        Next

currentrow is the current row of comma separated data read from an external file (readfields). The number of items will probably vary so building this dynamically is, in my old mind, the best way to go.
I'm seeing the boxes where the label should be, but nothing in the box. Why not?

Since I'm asking stupid questions, on 'form1' I can't seem to find the 'scrollbar' option and I will need to allow scroll bars to see all of the items.
For those interested, I'll also be adding another column which contains the names of fields from another file and then between then a drop area to allow me to equate one field with the other. Once the fields are related, I'll process the second file moving data between the fields in the second file to the corresponding fields in another file. Any suggestions on how to proceed will be much appreciated.
//al
 
The following code works ... apparently the location and text need to be added after the label is added to the control ... not sure, no, I don't understand why.
VB.NET:
        Dim lrow As Integer = 60
        Dim lcol As Integer = 25
        ReDim lblqus(currentrow.Length)
        For i = 0 To currentrow.Length - 1
            lblqus(i) = New Label With {
                .Name = "lblqus" & i + 1,
                .Size = New Size(200, 18),
                .Visible = True,
                .BorderStyle = BorderStyle.FixedSingle,
                .Font = New Font("Microsoft Sans Serif", 10, FontStyle.Regular),
                .BackColor = Color.MistyRose
            }
            'set the location
            Controls.Add(lblqus(i))
            lblqus(i).Location = New Point(lcol, lrow)
            lrow += 25
            lblqus(i).Text = currentrow(i).ToString
        Next

I also found autoscroll, it wasn't where I thought I remembered it.
Sorry for taking up your times //al
 
I'm not sure why there was an issue but it's not true that you have to set the Text and Location after adding the control to the form. Apart from that, you should use a TableLayoutPanel or FlowLayoutPanel to handle the layout automatically and not set the Location at all.
 
Have you considered using a DataGridView instead?

For those interested, I'll also be adding another column which contains the names of fields from another file and then between then a drop area to allow me to equate one field with the other. Once the fields are related, I'll process the second file moving data between the fields in the second file to the corresponding fields in another file. Any suggestions on how to proceed will be much appreciated

I'm not really clear on what UI youre aiming to do from this description, perhaps a description of the files you have and the file you want would be clearer. Or a screenshot/sketch. Or both

It sounds like you have two files, like:

VB.NET:
Name,Age,EnrollDate
John,60,1970-01-01


FirstName,JoinDate,Years
Mary,2010-01-01,20

And you want to have a UI that declares Name=FirstName, Age=Years, EnrollDate=JoinDate and then pump out a file like:

VB.NET:
Name,Age,EnrollDate
John,60,1970-01-01
Mary,20,2010-01-01

When asking for help consider that you often have two problems; the first is the actual problem youre trying to solve (this is problem X), the second is the problem you've hit while trying to implement the solution you've decided on for X (this is problem Y).
Strive to tell us X in addition/preference to Y - we'll help you with Y, sure, but we might be more interested in providing a solution for X because we may well be able to see an easier/more robust option etc than your Y

(For example you appear to be trying to implement a grid UI; it's easier to just load your data into a datatable and then bind it to a datagridview - perhaps two lines of code. If you want the cells rose pink, we can do that too)
 
Last edited:
Back
Top