How to add list items for a combo box
private void cb_avg_weeks_month_SelectedIndexChanged(object sender, EventArgs e)
{
cb_avg_weeks_month.Items.Add('1');
cb_avg_weeks_month.Items.Add('2开发者_C百科');
cb_avg_weeks_month.Items.Add('3');
}
Note:
cb_avg_weeks_month
describes the name i have assigned to my combo box.Well if you're only adding items to your combo box when the selected index has changed, then it'll never run because there aren't any items for the user to change the index on.
Populate your combo-box in your form's constructor after InitializeComponent();
if you work in Visual Studio you can add items to comboBox using comboBox's property. if you want to do it using code, you can do it in constructor:
public Form1()
{
cb_avg_weeks_month.Items.Add('1');
cb_avg_weeks_month.Items.Add('2');
cb_avg_weeks_month.Items.Add('3');
}
精彩评论