Simple introduction to VB.Net required

BenJervis

New member
Joined
Oct 11, 2011
Messages
2
Programming Experience
10+
Hi all

I am new to VB.Net, so please be gentle. I am natively an ASP.Net developer and wish to make a windows application to use in my place of business.

Requirements:

I have a database with a number of records in. I need to loop through these records in my application and list them in a particular order. I need a button next to each of the records to navigate through to another page for more information on the record. This list needs to be updated every n. seconds.

Where I am up to:

I have a timer which runs correctly every 5 seconds.
I have a successful database connection and have written a class to iterate through any records I tell it to. This is working as expected.

The problem:

I am attempting to use the following to write out my controls to the screen:

VB.NET:
        For Each DR In SQL.Exec("sp_GetList").Tables(0).Rows


            Dim oPanel As New Panel


            Dim oLabel As New Label
            oLabel.Text = DR("Record_Name")


            Dim oButton As New Button
            oButton.Text = "View"
            oButton.Anchor = DR("Record_ID")
            oButton.Left = 100
            AddHandler oButton.Click, AddressOf DoButtonClick


            oPanel.Controls.Add(oButton)
            oPanel.Controls.Add(oLabel)


            pnlList.Controls.Add(oPanel)




        Next

No matter what I try, each panel is overlayed on top of the last. I have tried adding a dynamic "top" (oPanel.Top = iTop / iTop += 30) to each panel which increases every time it iterates through the records, but this had no effect.

Thanks in advance. Do let me know if I have not provided enough information.

Ben
 
That's not a good approach. If you want to repeat a set of controls then you should do one of two things:

1. Use the DataRepeater control.
2. Create a UserControl and then add instances to a TableLayoutPanel.
 
Hi, thanks for your reply.

I have looked in my toolbox and cannot see a DataRepeater control - is this something I need to install or do something special to use?

I am happy to implement either of your suggestions - would it be possible, using my code above, to provide me with some simple example to get me started please?

I appreciate your help.

Ben
 
DataRepeater is found in PowerPacks tab in Toolbox. DataRepeater Control (Visual Studio)
UserControl from project menu 'Add User Control'. Designer for this is like for forms, add controls and code to it. You already know how to create and configure instances and add them to a containers Controls collection. TableLayoutPanel, or FlowLayoutPanel, are containers that you can add to a form.
 
Back
Top