Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

How to use "AddRange" method ?

kishore_peddikishore_peddi Member Posts: 176

Hi,

I have a dataset contains some records. I want to iterate through the loop until all the records are over. I will create an instances of "Panel" controls like below for each iteration.

Panel P = new Panel();
P.Location = new Point(PLocationX,PLocationY);

I am gettting the "PLocationX" & "PLocationY" from database.

My problem is how to use "AddRange" method so that i can add all the "Panles" to the form dynamically !!

if i write

this.Controls.AddRange(new Windows.Forms.Controls[] (P))

it is creating only one instance of Panel but not all !!

Advance ThanX for your time & patience.

Cheers,
Kishore

Comments

  • Alex81Alex81 Member Posts: 2
    : Hi...
    : I think you can use something like this:
    :
    : Panel p = null;
    : ArrayList arr = new ArrayList();
    : int PLocationX, PLocationY;
    :
    : foreach(DataRow row in MyDataSet.Tables["MyTable"].Rows)
    : {
    : // Calculate PLocationX and PLocationY
    : p = new Panel();
    : p.Location = new Point(PLocationX, PLocationY);
    : arr.Add(p);
    : }
    :
    : And at the end of the foreach block, use the ToArray() method of the class ArrayList that returns an object array... this is something you can pass to the AddRange method as follows:
    :
    : this.Controls.AddRange(arr.ToArray());
    :
    : I hope this will be helpful for you...
    : If you want to share more things like these, just contact me in avilesx@hotmail.com, my name is Alex...
    : Bye...


    : Hi,
    :
    : I have a dataset contains some records. I want to iterate through the loop until all the records are over. I will create an instances of "Panel" controls like below for each iteration.
    :
    : Panel P = new Panel();
    : P.Location = new Point(PLocationX,PLocationY);
    :
    : I am gettting the "PLocationX" & "PLocationY" from database.
    :
    : My problem is how to use "AddRange" method so that i can add all the "Panles" to the form dynamically !!
    :
    : if i write
    :
    : this.Controls.AddRange(new Windows.Forms.Controls[] (P))
    :
    : it is creating only one instance of Panel but not all !!
    :
    : Advance ThanX for your time & patience.
    :
    : Cheers,
    : Kishore
    :
    :



Sign In or Register to comment.