How do I print an array in Windows Forms from Visual Studio?

2

How can I print an array in windows forms? I tried the listbox using this code:

 public void Mostrar_Grafo(int Qtdlinha,int Qtdcoluna, string[,] MAdjacencia)
    {
        ListBox listbox1 = new ListBox();
        listbox1.Size = new System.Drawing.Size(400, 400);
        listbox1.Location = new System.Drawing.Point(10, 10);
        this.Controls.Add(listbox1);
        listbox1.MultiColumn = true;
        listbox1.BeginUpdate();

        listbox1.Items.Add("Matriz de Adjacencia");
        listbox1.Items.Add("");

        for (int i = 0; i < Qtdlinha; i++)
        {
            for (int j = 0; j < Qtdcoluna; j++)
            {
                listbox1.Items.Add(" " + MAdjacencia[i, j] + " ");
            }
        }
    }

But it shows the numbers in a disorganized way as shown in the figure below:

I need it to show in array format like this example:

0 1 0 0 0 0 0
1 0 1 0 0 0 0
0 1 0 1 1 1 0
0 0 1 0 1 1 0
0 0 1 1 1 1 0
0 0 1 1 1 0 0
0 0 0 0 0 1 1
    
asked by anonymous 23.10.2017 / 05:27

1 answer

4

You need to mount the array row before adding it to the listbox:

for (int i = 0; i < Qtdlinha; i++)
{
    string linha = "";

    for (int j = 0; j < Qtdcoluna; j++)
    {
        linha += " " + MAdjacencia[i, j] + " ";
    }

    listbox1.Items.Add(linha);
}
    
23.10.2017 / 06:05