2

绑定到 a的ValueMamberfor a是什么?ComboBoxList<string>

我正在使用 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; }
4

1 回答 1

5

From MSDN

If a property is not specified in ValueMember, SelectedValue returns the results of the ToString method of the object.

Edit based on update

You'll get an ArgumentException with your code because System.String is not a property that can be resolved (your string objects don't have a property called System.String). The default value, from MSDN, will be an empty string ("").

In this case, you don't need to set the ValueMember property and so you can use SelectedItem instead.

cmbForms.DataSource = Forms;
if (!string.IsNullOrWhiteSpace(PhotoDescription.Details.Form))
{
   cmbForms.SelectedItem = PhotoDescription.Details.Form;
}
于 2013-09-28T10:57:53.627 回答