winForm中combobox如何点击回车弹出下拉列表
如题 --------------------编程问答-------------------- 在按键里判断是不明是回车键,然后combobox1.DroppedDown=true; --------------------编程问答--------------------
--------------------编程问答-------------------- 楼上的方法好像不行。这样可以:
private void comboBox1_KeyPress(object sender, KeyPressEventArgs e)
{
if (e.KeyChar == (char)Keys.Return)
comboBox1.DroppedDown = true;
}
--------------------编程问答-------------------- 同意1,2楼。。。 --------------------编程问答--------------------
[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;
}
}
我想问下,如果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#