Fahad Aldaferi

Fahad Aldaferi

  • NA
  • 12
  • 4.9k

C# Database: combobox value base on another combobox. How?

Aug 1 2016 7:07 AM
I have an application that display some info from access 2016 database. - Form2 will display data from studentInfo table so Form2 will contain studentIDTextBox, studentNameComboBox, classComboBox, levelComboBox, studentDateDateTimePicker, nationalityComboBox, cityComboBox, provinceComboBox, blockTextBox...etc
 
levelComboBox:
  • SelectedValue: studentInfoBindingSource - Level
  • DataSource: studentLevelBindingSource
  • DisplayMember: Level
  • ValueMember: LevelID
classComboBox:
  • SelectedValue: studentInfoBindingSource - Class
  • DataSource: studentClassBindingSource
  • DisplayMember: Class
  • ValueMember: ClassID
 
Now my question is: Without effect the info has been display i want if i add a new item ( record ) to the database and when i choice a specific Level from levelComboBox it will change a list of classes within the selected Level in classComboBox and vice versa. How i can do that ?
I try to do that by using the code below but it is not good:
  1. private void provinceComboBox_SelectedIndexChanged(object sender, EventArgs e)  
  2. {  
  3.    var cityQuary =  
  4.       from displayCity in student1516DataSet.city  
  5.       where displayCity.ProvinceName == provinceComboBox.Text  
  6.       select displayCity;  
  7.   
  8.    cityComboBox.DataSource = cityQuary.AsDataView();  
  9. }  

Answers (7)