繁体   English   中英

如何将组合框的选定项获取到 c# 中的字符串变量

[英]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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM