//实践表明,不初始化combox控件的数据源,则无法对SelectedValue进行赋值 //因为赋值后赋值等式右边虽然有值,但SelectedValue确仍为空,具体什么原因不明? initializeDatasource(); dtp_makeDate.Text = item.WeighingDate.ToString(); txt_weighingTime.Text = item.WeightingTime; cmb_custName.SelectedValue =item.CusCode.ToString(); cmb_custName.Text = item.CusName;
看有个网站,有如下解释:
The SelectedValue property is used when you have linked the ComboBox to a data source, and want to return a value other than what is displayed.
For example, say you have a table called "City" which is made up of two fields, "ZipCode" and "CityName." You want to display to your application users the "CityName" value, but you are interested in storing the "ZipCode" value for the selected item.
With your ComboBox control, you set the following properties:
ComboBox.DataSource=City
ComboBox.DisplayMember=CityName
ComboBox.ValueMember=ZipCode
The ComboBox.SelectedItem will be CityName, but ComboBox.SelectedValue will be ZipCode.