[英]How to get the selected item of a combo box to a string variable in c#
谁能告诉我如何将ComboBox
的选定项目获取到string
变量?
string selected = cmbbox.SelectedItem.ToString();
MessageBox.Show(selected);
这给了我MessageBox
中的System.Data.DataRowView
尝试这个:
string selected = this.ComboBox.GetItemText(this.ComboBox.SelectedItem);
MessageBox.Show(selected);
您可以使用如下:
string selected = cmbbox.Text;
MessageBox.Show(selected);
测试这个
var selected = this.ComboBox.GetItemText(this.ComboBox.SelectedItem);
MessageBox.Show(selected);
var selected = cmbbox.GetItemText(cmbbox.Text); MessageBox.Show(选中);
SelectedText = this.combobox.SelectionBoxItem.ToString();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.