当前位置:编程学习 > C#/ASP.NET >>

winForm中combobox如何点击回车弹出下拉列表

如题 --------------------编程问答-------------------- 在按键里判断是不明是回车键,然后
combobox1.DroppedDown=true; --------------------编程问答--------------------

        private void comboBox1_KeyPress(object sender, KeyPressEventArgs e)
        {
            if (e.KeyChar == (char)Keys.Return)
                comboBox1.DroppedDown = true;
        }
--------------------编程问答-------------------- 楼上的方法好像不行。这样可以:

        [DllImport("user32.dll")]

        public static extern int SendMessage(IntPtr hWnd, int Msg, int wParam, int lParam);
        const int CB_SHOWDROPDOWN = 0x014F;
        const int CB_GETDROPPEDSTATE = 0x0157;

        private void comboBox1_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Enter)
            {
                    SendMessage(comboBox1.Handle, CB_SHOWDROPDOWN, 1, 0);
                    e.Handled = true;
            }
        }
--------------------编程问答-------------------- 同意1,2楼。。。 --------------------编程问答--------------------
引用 3 楼 computerfox 的回复:
楼上的方法好像不行。这样可以:

C# code

        [DllImport("user32.dll")]

        public static extern int SendMessage(IntPtr hWnd, int Msg, int wParam, int lParam);
        const int CB_SHOWDROPDOWN = 0x01……

我想问下,如果combobox是在dataGridView中的,应该怎么用啊 --------------------编程问答-------------------- 试试两个控件放在一起用,当点击一个是可以让一个隐藏,并且清空 --------------------编程问答-------------------- if (e.KeyCode == Keys.Enter&& comboBox1.DroppedDown == false)
            { e.Handled = true;
                SendKeys.SendWait("{F4}");
            } --------------------编程问答--------------------   private void comboBox1_KeyPress(object sender, KeyPressEventArgs e)
        {
            if (e.KeyChar == (char)Keys.Return)
                comboBox1.DroppedDown = true;
        }
补充:.NET技术 ,  C#
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,