|
■No76948 (魔界の仮面弁士) に追記 > SelectedIndex の呼びだしを、親フォームの Load / Shown イベントで > 行うようにするという手もあります。
// -------- 案1 -------- private void LoadItems() { this.MakeTableColumnsName(new string[] { "NO", "NAME" }); this.MakeTableAddRowDatas(new object[] { 1, "北海道" }); this.MakeTableAddRowDatas(new object[] { 1, "青森" }); this.DataSource = this.Table; this.DisplayMember = "NAME"; }
protected override void OnBindingContextChanged(EventArgs e) { base.OnBindingContextChanged(e); int defaultIndex = 1; // ★ this.SelectedIndex = Math.Min(defaultIndex, this.Items.Count - 1); }
// -------- 案2 -------- private void LoadItems() { this.MakeTableColumnsName(new string[] { "NO", "NAME" }); this.MakeTableAddRowDatas(new object[] { 1, "北海道" }); this.MakeTableAddRowDatas(new object[] { 1, "青森" }); this.DataSource = this.Table; this.DisplayMember = "NAME";
int defaultIndex = 1; // ★
EventHandler select = null; select = delegate { if (this.Created) { this.SelectedIndex = Math.Min(defaultIndex, this.Items.Count - 1); this.VisibleChanged -= select; } }; this.VisibleChanged += select; }
// -------- 案3 -------- private void LoadItems() { this.MakeTableColumnsName(new string[] { "NO", "NAME" }); this.MakeTableAddRowDatas(new object[] { 1, "北海道" }); this.MakeTableAddRowDatas(new object[] { 1, "青森" }); this.DataSource = this.Table; this.DisplayMember = "NAME";
int defaultIndex = 1;
EventHandler select = null; select = delegate { this.SelectedIndex = Math.Min(defaultIndex, this.Items.Count - 1); Application.Idle -= select; }; Application.Idle += select; }
|