想要咨询关于comboBox的select索引

时间:2012-05-30 06:04:43

标签: c#

我有comboBox,我填写这样的数据:

SQL = "select DISTINCT ActionNum,ActionName from ActionType";
adp = new SqlCeDataAdapter(SQL, Main.Conn);
adp.Fill(dsView, "ActionType");
adp.Dispose();
Mycom.DataSource = dsView.Tables[0];
Mycom.DisplayMember = dsView.Tables[0].Columns[1].ColumnName;
Mycom.ValueMember = dsView.Tables[0].Columns[0].ColumnName;

如何选择Mycom.ValueMember = 33

所在的组合框

(类似于Mycom.SelectedIndex = ???)

2 个答案:

答案 0 :(得分:2)

使用SelectedValue

Mycom.SelectedValue = 33;

答案 1 :(得分:1)

请参阅msdn for combobox。

http://msdn.microsoft.com/en-us/library/system.windows.forms.combobox.aspx

SelectedIndex   Gets or sets the index specifying the currently selected item. (Overrides ListControl.SelectedIndex.)
SelectedItem    Gets or sets currently selected item in the ComboBox.
SelectedText    Gets or sets the text that is selected in the editable portion of a ComboBox.
SelectedValue   Gets or sets the value of the member property specified by the ValueMember property. (Inherited from ListControl.)