Adding rows from an array to a list view Window Form

0

I am doing a project to solve the binomial of newton, this part is easy I was able to solve the problem in the console the way I wanted, I am now migrating to Windows Form and I have a problem to print the triangle of pascal in a listbox . I want to print on this formed

[1]

[1] [1]

[1] [2] [1]

[1] [3] [3] [1]

[1] [4] [6] [4] [1]

But I can not do this in the list box, it ends up printing one on top of the other.

[1]

[1]

[1]

[1]

[2]

[1] The code I used to do on the console.

int n;
   Console.WriteLine("Digite o valor de  N");
                n = int.Parse(Console.ReadLine());
                n = n + 1;
                matriz_triangulo = new int[n, n];
  Console.WriteLine("Digite o valor de  N");
                n = int.Parse(Console.ReadLine());
                n = n + 1;
                matriz_triangulo = new int[n, n];



            for (int linha = 0; linha < n; linha++)
            {
                for (int coluna = 0; coluna < n; coluna++)
                {
                    if (linha == coluna || coluna == 0)
                    {
                        matriz_triangulo[linha, coluna] = 1;
                    }
                    else if (linha != 0 && coluna != 0)
                    {
                        matriz_triangulo[linha, coluna] = matriz_triangulo[linha - 1, coluna - 1] + matriz_triangulo[linha - 1, coluna];
                    }
                }
            }
            for (int linha = 0; linha < n; linha++)
            {
                for (int coluna = 0; coluna < n; coluna++)
                {
                    if (matriz_triangulo[linha, coluna] != 0 && matriz_triangulo[linha, coluna] != 0)
                        Console.Write("[" + matriz_triangulo[linha, coluna] + "] ");
                }
                Console.WriteLine();
            }
    
asked by anonymous 15.11.2017 / 18:23

1 answer

0

Solution

for (int linha = 0; linha < n; linha++)
            {
                string linhaListBox = "";
                for (int coluna = 0; coluna < n; coluna++)
                {
                    if (triangulo_pascal[linha, coluna] != 0 && triangulo_pascal[linha, coluna] != 0)
                        linhaListBox += "[" + triangulo_pascal[linha, coluna] + "] ";
                }
                lbx_trianguloPascal.Items.Add(linhaListBox);
            }
    
15.11.2017 / 18:39