.net 如何在C#中将组合框的选定项转换为字符串变量

hpxqektj  于 2022-11-19  发布在  .NET
关注(0)|答案(5)|浏览(143)

谁能告诉我如何将ComboBox的选定项转换为string变量?

string selected = cmbbox.SelectedItem.ToString();
MessageBox.Show(selected);

这将得到MessageBox中的System.Data.DataRowView

vm0i2vca

vm0i2vca1#

试试看:

string selected = this.ComboBox.GetItemText(this.ComboBox.SelectedItem);
MessageBox.Show(selected);
vyswwuz2

vyswwuz22#

您可以使用如下:

string selected = cmbbox.Text;
MessageBox.Show(selected);
lb3vh1jj

lb3vh1jj3#

测试this

var selected = this.ComboBox.GetItemText(this.ComboBox.SelectedItem);
  MessageBox.Show(selected);
eoigrqb6

eoigrqb64#

var selected = cmbbox.GetItemText(cmbbox.Text);
MessageBox.Show(selected);
eagi6jfj

eagi6jfj5#

SelectedText = this.combobox.SelectionBoxItem.ToString();

相关问题