1. First, bind an "nclass table" in the database tutorial"
Show sourceview sourceprint? 1 dataset ds = getdataset ("select * from nclass ");
2 this. combobox1.displaymember = "classname ";
3 this. combobox1.valuemember = "classid ";
4 this. combobox1.datasource = ds. tables [0];
"Displaymember" attribute: in the most popular words, it is to be displayed to the user, bind the "classname" Field of the "nclass" table in the database;
"Valuemember" attribute: gets or sets the value of an attribute. The value is bound to the "classid" Field of "nclass" in the database;
Dataset ds = getdataset ("select * from nclass ");
This. combobox1.displaymember = "classname ";
This. combobox1.valuemember = "classid ";
This. combobox1.datasource = ds. tables [0];
2. Test the value of the corresponding attribute after the combobox is selected:
Show sourceview sourceprint? 1 debug. writeline (this. combobox1.selectedindex); 2 3 debug. writeline (this. combobox1.selectedvalue. tostring (); 4 5 debug. writeline (this. combobox1.text); 6 7 debug. writeline (this. combobox1.selecteditem. gettype (); this. combobox1.selectedindex: if the first drop-down option in combobox is selected, this attribute is used to obtain the index value of the first drop-down option. The index value here is "0" and increases in turn;
This. combobox1.selectedvalue: this attribute obtains the value corresponding to the "classid" field of "nclass" in the database;
Debug. writeline (this. combobox1.selectedindex );
Debug. writeline (this. combobox1.selectedvalue. tostring ());
Debug. writeline (this. combobox1.text );
Debug. writeline (this. combobox1.selecteditem. gettype ());
This. combobox1.text: this attribute obtains the selected text content from the current drop-down menu;
This. combobox1.selecteditem. gettype (): this attribute gets the type of each row selected from the current drop-down menu.