这是我的代码 -
combo.DisplayMember = "Caption";
combo.ValueMember = "PortName";
combo.Items.Add(new { PortName = "port", Caption = "caption" });
//Null reference exception here-
String PortName = combo.SelectedValue.ToString();
我错过了什么?
更新-
//the following line has solved my problem- dynamic item = cmbPortNo.SelectedItem; string PortName = item.PortName;