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

本文关键字:组合 是什么 成员 列表 字符串 绑定 | 更新日期: 2023-09-27 18:33:04

绑定

List<string>ComboBoxValueMamber是什么?

我正在使用Windows表单和.NET Framework 4。

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

Forms在哪里:

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

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

来自MSDN

如果未在 ValueTMember 中指定某个属性,则 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;
}