背景: Sorted プロパティのみが異なる 2 つのコンボ ボックスがあります。omboBox1 の Sorted プロパティはtrueに設定され、comboBox2 の Sorted プロパティはfalseに設定されています。これら 2 つのコンボ ボックスのデータソース プロパティを再割り当て/リセットしようとすると、comboBox1 にはデータが表示されず、comboBox2 には表示されます。Sorted プロパティが原因で、comboBox1 のデータが正しく表示されないのはなぜですか?
以下に含まれるすべてのコード:
public partial class Form1 : Form
{
private string[] a8BitGames = { "Metroid", "Zelda", "Phantasy Star", "SB:S&SEP" };
private string[] a16BitGames = { "StarFox", "Link", "Final Fantasy", "Altered Beast" };
private List<string> lSomeList = null;
private List<string> lSomeOtherList = null;
public Form1()
{
InitializeComponent();
this.lSomeList = new List<string>(a8BitGames);
this.lSomeOtherList = new List<string>(a16BitGames);
this.comboBox1.DataSource = lSomeList;
this.comboBox2.DataSource = lSomeOtherList;
}
private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
{
this.IndexChanged(1);
}
private void IndexChanged(int comboBox)
{
this.comboBox1.DataSource = null;
this.comboBox1.DataSource = a16BitGames;
this.comboBox2.DataSource = null;
this.comboBox2.DataSource = a8BitGames;
}
private void comboBox2_SelectedIndexChanged(object sender, EventArgs e)
{
this.IndexChanged(2);
}
}
partial class Form1
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.comboBox1 = new System.Windows.Forms.ComboBox();
this.comboBox2 = new System.Windows.Forms.ComboBox();
this.SuspendLayout();
//
// comboBox1
//
this.comboBox1.FormattingEnabled = true;
this.comboBox1.Location = new System.Drawing.Point(13, 13);
this.comboBox1.Name = "comboBox1";
this.comboBox1.Size = new System.Drawing.Size(121, 21);
this.comboBox1.Sorted = true;
this.comboBox1.TabIndex = 0;
this.comboBox1.SelectedIndexChanged += new System.EventHandler(this.comboBox1_SelectedIndexChanged);
//
// comboBox2
//
this.comboBox2.FormattingEnabled = true;
this.comboBox2.Location = new System.Drawing.Point(13, 41);
this.comboBox2.Name = "comboBox2";
this.comboBox2.Size = new System.Drawing.Size(121, 21);
this.comboBox2.TabIndex = 1;
this.comboBox2.SelectedIndexChanged += new System.EventHandler(this.comboBox2_SelectedIndexChanged);
//
// Form1
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(284, 262);
this.Controls.Add(this.comboBox2);
this.Controls.Add(this.comboBox1);
this.Name = "Form1";
this.Text = "Form1";
this.ResumeLayout(false);
}
#endregion
private System.Windows.Forms.ComboBox comboBox1;
private System.Windows.Forms.ComboBox comboBox2;
}