List<String>
をComboBoxにバインドしています。私はこれを2つの方法で書きました。最初の方法では、ComboBox の出力は空でした。どこが間違っていたのですか?私を助けてください。これは私のコードです:
public class MaritalStatusComboBox:ComboBox
{
public MaritalStatusComboBox()
{
BindingSource bs = new BindingSource();
bs.DataSource = new List<string> {"Single","Married" };
}
}
そして第二の方法:
public class MaritalStatusComboBox:ComboBox
{
List<string> list = new List<string>() { "Single", "Married" };
public MaritalStatusComboBox()
{
this.Items.Clear();
foreach (string str in list)
{
this.Items.Add(str);
}
}
}
ComboBox の出力には次のものが含まれます: Single、Married、 Collection コレクションが ComboBox に表示されるのはなぜですか?