I have combo box of programme and another is courses..
when i select any programme combo box so courses combobox add courses with respect to programme...
the problem is when select another programme so previously programm's course also included in combobox..
i want to remove previously courses..in courses combobox.
private void Teacher_Courses_Load(object sender, EventArgs e)
{
MyConnection = new SqlConnection("Data Source=.;Initial Catalog=Bahria_Managment;Integrated Security=True");
MyDataAdapter = new SqlDataAdapter("select P_Name from tblProgramme", MyConnection);
MyDataSet = new DataSet();
MyDataAdapter.Fill(MyDataSet);
for (int i = 0; i < MyDataSet.Tables[0].Rows.Count; i++)
{
int j = 0;
string PName = (string)MyDataSet.Tables[0].Rows[i][j];
j++;
cmbProgramme.Items.Add(PName);
}
}
private void cmbProgramme_SelectedIndexChanged(object sender, EventArgs e)
{
cmbCourses.Items.Clear();
MyDataAdapter = new SqlDataAdapter("select C_Name from tblCourses where P_Name = '" + cmbProgramme.Text + "'", MyConnection);
MyDataAdapter.Fill(MyDataSet, "C_Name");
for (int i = 0; i < MyDataSet.Tables["C_Name"].Rows.Count; i++)
{
int j = 0;
string C_Name = (string)MyDataSet.Tables["C_Name"].Rows[i][j];
j++;
cmbCourses.Items.Add(C_Name);
}
}
}