Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

comboBox.SelectedItem problem

ComboBox is binding database

string str= comboBox1.SelectedItem.ToString();

the line gives System.Data.DataRowView value for str but not giving selected item name.

like image 946
sharon Avatar asked Dec 11 '25 09:12

sharon


2 Answers

try this

if (comboBox1.SelectedItem is DataRowView) {
  string sval = ((DataRowView)comboBox1.SelectedItem).Row["ColumnName"].ToString();
}
like image 119
DeveloperX Avatar answered Dec 12 '25 23:12

DeveloperX


If you want the text of the selected item, just use comboBox1.Text.

like image 42
Truong Hong Thi Avatar answered Dec 12 '25 22:12

Truong Hong Thi



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!