Public partial class combo box Binding data: Form
{
Public combo box Binding data ()
{
Initializecomponent ();
}
Private void btnbind_click (Object sender, eventargs E)
{
String SQL = "select * From classinfo ";
Sqlconnection conn = dbhelper. getconnection ();
Sqldataadapter SDA = new sqldataadapter (SQL, Conn );
Dataset DS = new dataset ();
SDA. Fill (DS );
Dbhelper. closeconnection (conn );
Datatable table = Ds. Tables [0];
// Bind a data source to the cboclass combo box
This. cboclass. datasource = table;
// Bind the text (that is, the column displayed to the user)
This. cboclass. displaymember = "classname ";
// Bind the value (usually the primary key column)
This. cboclass. valuemember = "classid ";
}
Private void cboclass_selectedindexchanged (Object sender, eventargs E)
{
// Selectedvalue gets the value of the option, and text gets the text of the option
MessageBox. Show (this. cboclass. selectedvalue + "-" + this. cboclass. Text );
}
}