Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Two dimensional array of textboxes

Posted on 2006-06-27
7
Medium Priority
?
348 Views
Last Modified: 2008-02-01
Hi,

I want to have a 2dimensional array of textboxes ...
I wrote this code..( learning C# so pls be patient)


                                                for (int x = 0; x<8; x++)
                  for (int i = 0; i<8; i++)
                  {
                         
                        System.Windows.Forms.TextBox[][]tb ;
----------------->            tb[x][i]=  new System.Windows.Forms.TextBox();
                        tb[x][i].Text = "";
                        tb[x][i].TabIndex = i;
                        tb[x][i].Size = new System.Drawing.Size(20,20);
                        tb[x][i].Location = new System.Drawing.Point(x*70, i*25);
                        tb[x][i].Text = i.ToString();
                        this.Controls.Add(tb[x][i]);
                  }

ERROR: Use of unassigned local variable 'tb'

How do i solve this
0
Comment
Question by:pai_prasad
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 2
7 Comments
 
LVL 13

Expert Comment

by:devsolns
ID: 16994675
System.Windows.Forms.TextBox[][]tb ;   <---just a reference to nothing.

need to make,
int size = 50;
System.Windows.Forms.TextBox[][]tb  = new System.Windows.Forms.TextBox[size][];
0
 
LVL 13

Expert Comment

by:devsolns
ID: 16994703

Alternatives as well,

                //Framework 1.1
                ArrayList list = new ArrayList();
                list.Add(new System.Windows.Forms.TextBox());

                //Framework 2.0
                System.Collections.Generic.List<System.Windows.Forms.TextBox> = new List<System.Windows.Forms.TextBox>();
                list.Add(new System.Windows.Forms.TextBox());


I would still learn to use arrays though.  They are a critical element in comptuer science.
0
 
LVL 10

Author Comment

by:pai_prasad
ID: 16994713
i tried that ...
System.Windows.Forms.TextBox[][]tb = new TextBox[8][];


it gives error: Object reference not set to an instance of an object. on

tb[x][i].Text = "";
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 13

Expert Comment

by:devsolns
ID: 16994963

see your not using a 2 dimensional array, your using an array of an array

int size = 50;
System.Windows.Forms.TextBox[][]tb  = new System.Windows.Forms.TextBox[size][];

int size2 = 2;
tb[0] = new System.Windows.Forms.TextBox[size2];


2d array looks like System.Windows.Forms.TextBox[,] tb = new System.Windows.Forms.TextBox[,] {{new System.Windows.Forms.TextBox(), new System.Windows.Forms.TextBox()}, {new System.Windows.Forms.TextBox(), new System.Windows.Forms.TextBox()}}

0
 
LVL 5

Accepted Solution

by:
AdGroot earned 2000 total points
ID: 16994977
try this

            System.Windows.Forms.TextBox[][] tb = new TextBox[8][];
            for (int x = 0; x < 8; x++)
            {
                tb[x] = new TextBox[8];
                for (int i = 0; i < 8; i++)
                {

                    tb[x][i] = new System.Windows.Forms.TextBox();
                    tb[x][i].Text = "";
                    tb[x][i].TabIndex = i;
                    tb[x][i].Size = new System.Drawing.Size(20, 20);
                    tb[x][i].Location = new System.Drawing.Point(x * 70, i * 25);
                    tb[x][i].Text = i.ToString();
                    this.Controls.Add(tb[x][i]);
                }
            }


Ad
0
 
LVL 10

Author Comment

by:pai_prasad
ID: 16995740
thanks for the answer,,

but how do i add a text_changed event listener and retrieve the value
any links for that?
0
 
LVL 13

Expert Comment

by:devsolns
ID: 16996218
are you kidding me, he took my answer and pasted it in code.  wonderful.
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article introduced a TextBox that supports transparent background.   Introduction TextBox is the most widely used control component in GUI design. Most GUI controls do not support transparent background and more or less do not have the…
Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
This course is ideal for IT System Administrators working with VMware vSphere and its associated products in their company infrastructure. This course teaches you how to install and maintain this virtualization technology to store data, prevent vuln…
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…

610 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question