i have two combo box1 and combo box 2. cb1 contain I - year., II - year., III - year... cb2 contains the first.,second.,third.,forth.,fifth.,sixth.,, now i have to split each two items given to I - year... respectively..
i.e I - year ( first & second).. II - year ( third & forth ).. III - year ( fifth & sixth )..
now.. i have to select I - year in cb1 means, first and second items only visible on cb2..
help me ... code for that in c#.net
Manu PrasadPosted Sep 10, 2015, 11:46 AM
public partial class Form1 : Form
{
Dictionary> cbsource = new Dictionary>();
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
//Intialize dictionary
cbsource.Add("Ist", new List { 1, 2 });
cbsource.Add("IInd", new List { 3, 4 });
cbsource.Add("IIIrd", new List { 5, 6 });
//Add items to first combobox
cb1.DataSource = cbsource.Keys.ToList();
}
//Add items dynamically to combobox 2
private void cb1_SelectedIndexChanged(object sender, EventArgs e)
{
cb2.DataSource = cbsource[cb1.SelectedItem.ToString()];
}
}