开发者

How to add list items for a combo box

I have tried to create items for a combo box but it is not working.Please help me out. This is what i have so far;

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');
} 
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜