-2

I have 2d array and how i can add this 2d array to tablelayoutpanel?

string[,] mayinlar = new string[20, 20];
        for(int i = 0; i < mayin ; i++)
        {
            int j = rnd.Next(0, 20);
            int k = rnd.Next(0, 20);
            mayinlar[j, k] = "x";
        }
2
  • 2
    Sorry but your question is not clear enough, Do you want to show your array in WinForm control like DataGridView or what? Commented Dec 8, 2019 at 15:11
  • I want make a minesweeper and im create 2d array for mines so i want show this mines on tablelayoutpanel Commented Dec 8, 2019 at 15:15

1 Answer 1

0

It is not as simple as you asked for, but I can help you to show 2D array in a form. 1. Add a Listbox control and rename it to listBox1. (It's default name) 2. Add this code :

string x = null;
for (int i = 0; i < 19; i++)
{
    for (int j = 0; j < 19; j++)
    {
        x += (mayinlar[i, j])?.Length == 1 ? mayinlar[i, j] : " ";
    }
    listBox1.Items.Add(x);
    x = null;
}
Sign up to request clarification or add additional context in comments.

4 Comments

thanks for it but i cant use listbox because i making a minesweeper.
Making a game like minesweeper needs programming skills, So you have a good start. this link helps you to create form control in run-time. stackoverflow.com/questions/21633826/…
What do you think I should use? But button will not be used i will use arrow keys and dont have to steps mines.
Microsoft Minesweeper implemented blocks with button, But in a modern way, you can use System.Drawing namespace. this link provides you with the complete solution:rosettacode.org/wiki/Minesweeper_game

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.