Label Array

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • heyhey
    New Member
    • Mar 2009
    • 2

    #1

    Label Array

    I have searched the forums and although i get hits on my searches no matches have answered my quandary. I am using visual studio 2008

    So to the question:

    I have 10 label's named label1, label2 label3 etc. and i have a dataset with 2 fields and 10 rows (2x10)

    i would like to create a for loop like the following:

    for x = 1 to 10
    label(x) = ds.row(x).field (0)
    next

    ps. please excuse the syntax for the dataset command.
  • aryanbs
    New Member
    • Mar 2009
    • 42

    #2
    You said dataset, right?

    for x as integer = 1 to 10
    me.controls("la bel" & x.ToString()).T ext =ds.Tables(0).R ows(x-1).Item(0).ToSt ring() '0 being first column
    next

    Comment

    • tlhintoq
      Recognized Expert Specialist
      • Mar 2008
      • 3532

      #3
      You could put the labels into an array or List<> and work them that way. Then their names don't matter.

      Code:
      label[] myLabelArray = {label0, label1, label2};
      // could just as easily read
      label[] myLabelArray = {lblFirstName, lblLastName, lblAddress, lblCity};
      // which is much easier to read
      for (int x = 0; x<myLabelArray.length; x++)
      {
         myLabelArray[x].text = ds.row[x].field[0];
      }

      Comment

      • heyhey
        New Member
        • Mar 2009
        • 2

        #4
        :)

        Thanks guys.

        I shall try this as soon as i get home tonight so fingers crossed.

        Comment

        Working...