Hi
i have an array i am allotting array values through a loop now i want to add each value of an array in a text box. here is my code

private void btnFramCode_Click(object sender, EventArgs e)
        {
            int Row = Convert.ToInt32(tbRows.Text);
            int Column = Convert.ToInt32(tbColumns.Text);

            int[,] arr = new int[Column, Row];
            for (int k = 0; k < Column; k++)
            {
                for (int l = 0; l < Row; l++)
                {
                        arr[k,l] = 0;
                        tbArray.Text = ;// tbArray is a textbox should i use this here if yes what should i write after assignment
                }
            }

Recommended Answers

All 7 Replies

What do you expect to see in the textbox as there are at least a billion different ways of displaying numbers. Without knowing what you want, how can someone tell you how to get it?

As Momerath said, please tell us what do you want to have in textBoxes, otherwise here is a simple example of a textBoxes array and a loop to insert text into them:

TextBox[] tbs = new TextBox[] {textBox1, textBox2, textBox3 }; //put all of them in here!
//then loop:
for(int i = 0; i < tbs.Lenght; i++)
{
   if(tbs[i] != null) //if needed, if not remove this line!
      tbs[i].Text = "some text + i.ToString();
}

Would a DataGridView not be a better idea?

i guess i was unable to explain it properly..
ok basically i am making a bit map application there would be an array of buttons i can make fonts or figures
Now those buttons will return 1 for the pressed one and 0 for unpressed in this way i would have an array like
if (0,0)th button is pressed it will return
1x1 so on
in this way i want to have this array in a text box with comma separated like
1x1,0x1,0x0,...
hopefully i was able to explain it

@ ddanbe thanks for suggestion but it wont work as i have to use this array in another application

@ Mitja i ant to add array in a single textbox

So, please tell me if I'm wrong.
You would like to have a 2D array of zeros and ones in a textbox, separated by commas. What would 0x1 mean?
If you know the dimensions of your array it is easy to calculate wich button is on or off if you have a text like this: 0,0,1,0,1,1,1,0,0,0,1,0,1,0......

yes you are right i wrote wrong there
so how it would be possible

got it

private void btnFramCode_Click(object sender, EventArgs e)
        {
            
            int[,] arr = new int[Column, Row];
            for ( i = 0; i < Column; i++)
            {
                for ( j = 0; j < Row; j++)
                {
                    arr[i, j] = 0;
                    if (buttons[i,j].BackColor==Color.Red)
                        arr[i,j] = 1;
                    tbArray.Text = tbArray.Text + arr[i,j] + ",";
                        
                }
            }
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.