1, first, bind a "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 their most popular words, is to show to the user, the Binding database table "NClass" of the "ClassName" field;
ValueMember property: Gets or sets the value of a property that is bound to the "classid" field of the table "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, after the test ComboBox selected, what is the value of the corresponding property:
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 at this time, this property is the index value for the current first drop-down option, and I have the index value "0", incremented sequentially;
This.combobox1.selectedvalue: This property obtains the corresponding value of the "ClassID" field in the table "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 property gets the text content selected in the current Drop-down menu;
This.combobox1.selecteditem.gettype (): This property gets the type of each row object that the current Drop-down menu selects