Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. handling control array in runtime

handling control array in runtime

Scheduled Pinned Locked Moved C#
databasehelpdata-structurestutorial
3 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • V Offline
    V Offline
    vatzcar
    wrote on last edited by
    #1

    i'm trying to implement control array in my app. the no of control will depend on user's requirement. total number will be gathered from database. therefore i had to make the code within a method. private void CreatePictureBoxes() { .... .... PictureBox[] pcbMem = new PictureBox[intCount]; Label[] lblMem = new Label[intCount]; .... } since i'm doing the whole code in a method i can't access those controls outside of that method. it's also not possible for me to create them in class level as the total index is unkown to me initially. i don't know how to reasign the length of an array so it's being a problem for me. so please help me out to creating the controls so that i can use them from anywhere.

    S J 2 Replies Last reply
    0
    • V vatzcar

      i'm trying to implement control array in my app. the no of control will depend on user's requirement. total number will be gathered from database. therefore i had to make the code within a method. private void CreatePictureBoxes() { .... .... PictureBox[] pcbMem = new PictureBox[intCount]; Label[] lblMem = new Label[intCount]; .... } since i'm doing the whole code in a method i can't access those controls outside of that method. it's also not possible for me to create them in class level as the total index is unkown to me initially. i don't know how to reasign the length of an array so it's being a problem for me. so please help me out to creating the controls so that i can use them from anywhere.

      S Offline
      S Offline
      Stefan Troschuetz
      wrote on last edited by
      #2

      vatzcar wrote:

      it's also not possible for me to create them in class level as the total index is unkown to me initially

      Just declare them at class level and instanciate them inside the method.

      PictureBox[] pcbMem;
      Label[] lblMem;

      private void CreatePictureBoxes()
      {
      ....
      ....
      this.pcbMem = new PictureBox[intCount];
      this.lblMem = new Label[intCount];
      ....
      }


      "Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning." - Rick Cook

      www.troschuetz.de

      1 Reply Last reply
      0
      • V vatzcar

        i'm trying to implement control array in my app. the no of control will depend on user's requirement. total number will be gathered from database. therefore i had to make the code within a method. private void CreatePictureBoxes() { .... .... PictureBox[] pcbMem = new PictureBox[intCount]; Label[] lblMem = new Label[intCount]; .... } since i'm doing the whole code in a method i can't access those controls outside of that method. it's also not possible for me to create them in class level as the total index is unkown to me initially. i don't know how to reasign the length of an array so it's being a problem for me. so please help me out to creating the controls so that i can use them from anywhere.

        J Offline
        J Offline
        jjansen
        wrote on last edited by
        #3

        vatzcar wrote:

        i don't know how to reasign the length of an array so it's being a problem for me.

        To solve this problem, you could use a generic list. using System.Collections.Generic; List pcbMem = new List(); Private void CreatePictureBoxes() { ... for (int i = 0; i < intCount; i++) { PictureBox myPcb = new PictureBox(); ... pcbMem.Add(myPcb); } }

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups