no jelikoz pises ze si zacatecnik tak asi nema cenu vysvetlovat jak navrhnout architekturu aplikace abys dosahl pozadovane funkcionality, takze posilam "zbastleny" kod ktery to vyresi
public partial class Form1 : Form
{
private List<RadioItem> Data;
private List<RadioItem> CurrentData;
public Form1()
{
InitializeComponent();
Data = new List<RadioItem>()
{
new RadioItem()
{
Title = "titulek1",
SubItems = new List<RadioItem>()
{
new RadioItem()
{Title = "l1 tit1"},
new RadioItem()
{Title = "l1 tit2"},
}
},
new RadioItem()
{
Title = "titulek2",
SubItems = new List<RadioItem>()
{
new RadioItem()
{Title = "l2 tit1"},
new RadioItem()
{Title = "l2 tit2"},
new RadioItem()
{
Title = "l2 tit3",
SubItems = new List<RadioItem>()
{
new RadioItem() {Title = "l2 l3 tit1"},
new RadioItem() {Title = "l2 l3 tit2"}
}
},
}
},
};
CurrentData = Data;
GenerateRadioButtons();
}
private void button1_Click(object sender, EventArgs e)
{
var checket = groupBox1.Controls.OfType<RadioButton>().FirstOrDefault(o => o.Checked);
if (checket != null)
{
var d = checket.Tag as RadioItem;
if (d.SubItems == null)
MessageBox.Show("konecna volba: " + d.Title);
else
{
CurrentData = d.SubItems;
GenerateRadioButtons();
}
}
}
private void GenerateRadioButtons()
{
groupBox1.Controls.Clear();
int i = 0;
foreach (var x in CurrentData)
{
groupBox1.Controls.Add(new RadioButton() {Text = x.Title, Top=(i++)*30+20, Left=10, Tag=x});
}
}
private void button2_Click(object sender, EventArgs e)
{
CurrentData = Data;
GenerateRadioButtons();
}
}
public class RadioItem
{
public string Title { get; set; }
public List<RadioItem> SubItems { get; set; }
}
projekt je WinForm a formular pocita se 2 tlacitkama a grouboxem. tu mas odkaz na solution + exac
https://mega.co.nz/#!yxgUWRCB!WalzxAejaMPTtFL56wXR1il9MuDpJ64LdBxcfNzfHR4