积极答复者
ComboBox的问题

问题
-
ComboBox,ID为:comstore
comstore.DataSource = list.Select(a => new { a.StoreId, a.SName }).Distinct().ToList(); comstore.DisplayMember = "SName"; comstore.ValueMember = "StoreId"; comstore.SelectedValue = "L110";
首先数据元{StoreId,SName}中有值“{StoreId:L110,SName:tttt}”
为什么语句
comstore.SelectedValue = "L110";
之后,comstore.SelectedValue 值为“StoreId:L110,SName:tttt”,而不是“L110”
大其心,可容天下之物; 虚其心,可受天下之善;
答案
-
你好:
在Dropdownlist的文档中,
SelectedValue Gets the value of the selected item in the list control, or selects the item in the list control that contains the specified value.
所以我建议你使用SelectedIndex来设置选择项。
SelectedIndex Gets or sets the index of the selected item in the DropDownList control.
如果这样也不行,请先绑定datasource,再设置选择项。
希望对你有所帮助。
I am here!- 已标记为答案 BoberSongModerator 2010年10月13日 7:08
全部回复
-
写SelectedValueChanged事件函数,让其返回comstore.StoreId.ToString()。
参见:http://msdn.microsoft.com/en-us/library/system.windows.forms.listcontrol.selectedvaluechanged.aspx
希望对您有帮助!
-
你好:
在Dropdownlist的文档中,
SelectedValue Gets the value of the selected item in the list control, or selects the item in the list control that contains the specified value.
所以我建议你使用SelectedIndex来设置选择项。
SelectedIndex Gets or sets the index of the selected item in the DropDownList control.
如果这样也不行,请先绑定datasource,再设置选择项。
希望对你有所帮助。
I am here!- 已标记为答案 BoberSongModerator 2010年10月13日 7:08