私は何かを理解しようとしています。ComboBox
名前付きの「cbSize」にいくつかのアイテムを追加するメソッドがあります。2 種類のデータを追加すると、コードがクラッシュすることがわかりました。これは、ComboBox
が 1 種類のデータしか収容できないためですか?
items.Add(1);
items.Add(10);
items.Add(100);
items.Add(2);
items.Add(20);
items.Add(3);
items.Add(30); //works fine if add numbers only
//items.Add("4"); //will crash if mix both numbers and text
//items.Add("2"); //works fine if add text only
//then sort them out
items.Sort();
//now clear original cbSize items
cbSize.Items.Clear();
//and add them back in sorted order
cbSize.Items.AddRange(items.ToArray());
//gotta clear ArrayList for the next time or else things will add up
items.Clear();