Jak uzyskać zaznaczony element pola combo do zmiennej łańcuchowej w c#

Czy ktoś może mi powiedzieć jak przenieść zaznaczoną pozycję ComboBox do zmiennej string?

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

To daje mi System.Data.DataRowView w moim MessageBox

 35

4 answers

Spróbuj tego:

string selected = this.ComboBox.GetItemText(this.ComboBox.SelectedItem);
MessageBox.Show(selected);
 59
Author: duDE,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2013-03-03 13:24:44

Możesz użyć jak poniżej:

string selected = cmbbox.Text;
MessageBox.Show(selected);
 8
Author: Omer K,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2016-09-29 10:28:00

Test this

  var selected = this.ComboBox.GetItemText(this.ComboBox.SelectedItem);
  MessageBox.Show(selected);
 6
Author: Shahrooz Jafari,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2017-05-23 12:34:14
SelectedText = this.combobox.SelectionBoxItem.ToString();
 -4
Author: vinod Jacob,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2016-03-10 21:33:51