creating array of controls (labels) in VB Express

Hello,

I'm trying to figure out how to create an array of controls in VB Express. I've read that somehow there's an automated way to do this (as in VB6, I presume, but I've never worked in VB6 either), but I can't find anywhere that describes it.

Basically, I have a table that I've created on one of my forms that is 18x20 cells. It would be really helpful if I could use an array to populate my table rather than having to write 360 lines of code (this is just a test database, so I only have 18 cases -- and I want to have a more succinct way of doing this for when I need to expand the functionality of my program to include more data).

For example, I'm currently populating the table one cell at a time as follows (it does the job, but it's cumbersome):

pid1.Text = rawdataRow(dist(0,1)).pid
ht1.Text = rawdataRow(dist(0,1)).ht
wt1.Text = rawdataRow(dist(0,1)).wt
etc.

where rawdataRow is reading the rows from my database, and dist(0,1) is the index from a distance matching function that indicates which row I should be retrieving info from, and pid1, etc. rep the specific cell in my table.

Any ideas


Answer this question

creating array of controls (labels) in VB Express

  • Kasinathan

    The DataGridView is very flexible and can be configured to present the data pretty much any way you want. When you say "sorted" I assume you mean "filtered" - showing only those rows that meet a certain criteria. You would typically use a database query to create a DataSet and bind that to your DataGridView control; you could the allow the users to sort the result by any column.

    As I mentioned in the earlier post, if you are new to Visual Basic you really should strat out by working through the Guided Tour - it will give you enough background to get started.

    - Steve Hoag

  • Simpzon

    Yes, I am trying to create a table out of Label controls, because I want to present sorted rows of data rather than just allow the user to browse the database. Prior to this step, I have calculated the "distance" of each case from the query case, and now I want to present the cases to the user in order of closest matched cases.

    Is there a better way to do this Does the DataGridView control allow you to sort the cases first

    Thanks for your help!

  • aaronmarissa

    VB 2005 doesn't support control arrays, but I'm not sure you're even headed in the right direction. It sounds like you are trying to construct a "table" out of a bunch of Label controls. If you are trying to display data from your database, why don't you simply bind the database to a DataGridView control

    If this is new to you, I suggest that you start by working through the "Managing Your Records" section of the Visual Basic Guided Tour for an introduction to working with databases: http://msdn2.microsoft.com/en-us/library/t25kbx0s(en-US,VS.80).aspx

    Hope this helps,
    Steve Hoag
    Visual Basic Express

  • creating array of controls (labels) in VB Express