Je peuplant les éléments ComboBox avec une liste en utilisant l'événement Click. Quand il est déjà rempli, MaxDropDownItems ne fonctionne pas. Est-ce que quelqu'un sait comment réparer celui-ci?ComboBox.MaxDopDownItems ne fonctionne pas lors de l'ajout des éléments en utilisant l'événement Click
Voici le code:
List<string> list = new List<string>();
ComboBox cb;
private void button1_Click(object sender, EventArgs e)
{
cb = new ComboBox();
cb.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
cb.FlatStyle = System.Windows.Forms.FlatStyle.Popup;
cb.FormattingEnabled = true;
cb.Size = new System.Drawing.Size(94, 21);
cb.MaxDropDownItems = 5;
cb.Click +=new EventHandler(cb_Click);
this.Controls.Add(cb);
}
private void cb_Click(object sender, EventArgs e)
{
foreach (string str in list)
{
cb.Items.Add(str);
}
}
private void Form1_Load(object sender, EventArgs e)
{
list.Add("1");list.Add("2");list.Add("3");
list.Add("4");list.Add("5");list.Add("6");
list.Add("7");
}
MaxDropDownItems est réglé sur 5 de sorte que le combobox doit montrer atleast 5 articles seulement: