いつもお世話になっております。
ComboBoxの項目表示について質問させて頂きます。
本プログラムは「Enterキー」を押すと、フォーカスが移動し、
移動先の ComboBox の項目を表示するというものです。
Enterキーでの ComboBox1 ⇄ ComboBox2 のフォーカス移動 & 表示は問題ないのですが、
Combobox1・2を左クリックすると一瞬項目が出るのですが、すぐ消えてしまいます。
現在:
1.Combobox1にフォーカスがある状態で、Combobox2の「∨」ボタン(Combobox右端の∨)をクリック。
2.一瞬項目が表示されるが、その後項目が消えてしまう。
3.再度、Combobox2の「∨」ボタンをクリックすると、項目が表示される。
理想:
1.Combobox1にフォーカスがある状態で、Combobox2の「∨」ボタンをクリック。
2.項目が表示される。
何か付け加える条件など必要なのでしょうか?
どなた様かご指導ご鞭撻の程よろしくお願い致します。
以下作成途中のプログラムソースを添付させて頂きます。
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace WindowsFormsApplication3
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
comboBox1.Items.Add("0: a "); comboBox1.Items.Add("1: b "); comboBox1.Items.Add("2: c "); comboBox2.Items.Add("0: X "); comboBox2.Items.Add("1: Y "); comboBox2.Items.Add("2: Z "); } ComboBox[] comboBoxArray = new ComboBox[2]; string[] comboValues = new string[2]; string cb1; string cb2; private void Form1_Load(object sender, EventArgs e) { this.KeyPreview = true; comboBoxArray[0] = comboBox1; comboBoxArray[1] = comboBox2; for (int i = 0; i < 2; i++) { comboBoxArray[i].Enter += new EventHandler(_Enter); } } public void _Enter(object sender, EventArgs e) { for (int i = 0; i < comboBoxArray.Length; i++) { if (Object.ReferenceEquals(sender, comboBoxArray[i])) { comboValues[i] = (comboBoxArray[i].Text); if(i == 0) { comboBox1.DroppedDown = true; } if (i == 1) { comboBox2.DroppedDown = true; } } } } private void Form1_KeyDown(object sender, KeyEventArgs e) { if (e.KeyCode == Keys.Enter) { if (!e.Control) { this.SelectNextControl(this.ActiveControl, true, true, true, true); } } } }
}
回答3件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2015/10/26 08:54