I need to keep checkboxes in a collection and access them via matrix coordinates.
The following example works but only if I know the size of the matrix beforehand, since an array is used.
What would be the best kind of approach/collection to achieve the same result but also allow the matrix to be defined at runtime, e.g. Dictionary<>, Tuple<>, KeyValuePair<>
?
using System;
using System.Windows;
using System.Windows.Controls;
namespace TestDoubarray
{
public partial class Window1 : Window
{
public Window1()
{
InitializeComponent();
CheckBox[,] checkBoxes = new CheckBox[10, 10];
for (int x = 0; x < 10; x++)
{
for (int y = 0; y < 10; y++)
{
CheckBox cb = new CheckBox();
cb.Tag = String.Format("x={0}/y={1}", x, y);
checkBoxes[x,y] = cb;
}
}
CheckBox cbOut = checkBoxes[4, 8];
Message.Text = cbOut.Tag.ToString();
}
}
}