2

にバインドされているValueMambera の forは何ですか?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 に答える