What is the best way to implement a 2D mesh switch?

What is the best way to implement a 2D grid of radio buttons so that you can select only one parameter in each column and one parameter in each row?

+3
source share
3 answers

1D array of 1D arrays of radio buttons. Each row (or column) will use the normal functionality of the switch, while each column (or row) will be updated with a loop called each time a separate switch is switched.

+2
source

Something like that?

using System; using System.Drawing; using System.Windows.Forms; class Program { static RadioButton[] bs = new RadioButton[9]; static void HandleCheckedChanged (object o, EventArgs a) { RadioButton b = o as RadioButton; if (b.Checked) { Console.WriteLine(Array.IndexOf(bs, b)); } } static void Main () { Form f = new Form(); int x = 0; int y = 0; int i = 0; int n = bs.Length; while (i < n) { bs[i] = new RadioButton(); bs[i].Parent = f; bs[i].Location = new Point(x, y); bs[i].CheckedChanged += new EventHandler(HandleCheckedChanged); if ((i % 3) == 2) { x = 0; y += bs[i].Height; } else { x += bs[i].Width; } i++; } Application.Run(f); } } 

Regards, Tamberg

0
source

You can approach this with a custom collection and snap buttons to it.

Each individual child will have a property for the row and a property for the column, as well as a true / false value flag that triggers an event when it is changed to true by pressing or pressing a key.

The collection class logic will respond to a value change and loop through other children in the same row and column to notify them that they should be false.

If you do not want to bind data, you can also do this with a set of user controls.

0
source

All Articles