繁体   English   中英

绑定到列表的组合框的值成员是什么<string>

[英]What is the Value Member for a combobox which is bind to a List<string>

绑定到列表的组合框的成员值是多少? 我正在使用Winform应用程序和.net Framework 4。

  cmbForms.DataSource = Forms;
  cmbForms.ValueMember="System.String";
  if (!string.IsNullOrWhiteSpace(PhotoDescription.Details.Form))
      {
          cmbForms.SelectedValue = PhotoDescription.Details.Form;
      }

表格在哪里

 public List<string> Forms{ get; set; }

MSDN

如果在ValueMember中未指定属性,则SelectedValue返回对象的ToString方法的结果。

根据更新进行编辑

您的代码会收到ArgumentException ,因为System.String不是可以解析的属性(您的string对象没有名为System.String的属性)。 MSDN的默认值将是一个空字符串("")

在这种情况下,您无需设置ValueMember属性,因此可以改用SelectedItem

cmbForms.DataSource = Forms;
if (!string.IsNullOrWhiteSpace(PhotoDescription.Details.Form))
{
   cmbForms.SelectedItem = PhotoDescription.Details.Form;
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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