The Combobox drop-down box is linked at two levels, and the combobox drop-down box is linked at two levels.
Two levels of interaction in the drop-down box is a situation that we often encounter during development. For example, in a student management system, the score of a student's examination is queried Based on the grade, subject, and name. The grades and subjects are limited data (databases) in the hard disk, and the students can be manually specified by users, at this time, there are two tables in the database: grade and subject. Each subject corresponds to a grade. Therefore, we can use two drop-down boxes (Combobox) to store grade and subject information for users to choose from. The interface is as follows:
Model expansion 1 int gradeid = Convert. toInt32 (cboGrade. selectedValue); // obtain the selected grade number 2 3 List = subjectBll. getAllSubject (gradeid); // you can call this operation to query the corresponding account information under the specified year ID. valueMember = "subjectid"; 6 cboSubject. displayMember = "subjectname"; 7 cboSubject. dataSource = list; 1 int gradeid = Convert. toInt32 (cboGrade. selectedValue); // obtain the selected grade number 2 3 List <Subject> list = subjectBll. getAllSubject (gradeid); // you can call this operation to query the corresponding account information under the specified year ID. valueMember = "subjectid"; 6 cboSubject. displayMember = "subjectname"; 7 cboSubject. dataSource = list;
SelectedValue attribute in the drop-down boxProperty prototype:
Common Errors:
Error Analysis: after the experiment, we can confirm that the code for binding the data source is placed behind the attribute settings to solve this error, I personally think that if you bind the data source first, the system will automatically set the valuemember attribute value to the type of the bound set and then set Valuemember, and the system will not change it!