dimanche 8 août 2021

C# / I fill up a DataGridView from a string array by picking the next cell randomly and do not want to pick used cell again

I have a string array and have to fill up a DataGridView with it by picking a random next cell. I want to use all items of the array but avoid to pick a cell I already filled up. It is fine if there are empty cells but I have to use all items.

What I tried:

foreach (var item in myarray)
        {
            y = random.Next(0, 5);
            x = random.Next(0, t.Rows.Count);
            t.CurrentCell = t[y, x];

            for (int j = 0; j < t.Columns.Count; j++)
            {
                
                for (int k = 0; k < t.Rows.Count; k++)
                {
                   
                    if (t.Rows[k].Cells[j].Value == null)
                    {
                        t.CurrentCell.Value = item;
                    }
                }
            }
        }

                    

Many thanks!




Aucun commentaire:

Enregistrer un commentaire