日期:2014-05-17  浏览次数:20373 次

winform中combobox的问题
1:只有在点击下拉列表的箭头的时候,下拉列表才可以下拉。如果只是点击别的地方,只能选中,而不能下拉。
2:由于这个combobox在gridview中,如果从一个cell(用方向键)到这个combobox时候,也不可以下拉,只能选中。
请各位指点。如果说的不明白,我再解释一下。

------解决方案--------------------
当初始化时,要通过combobox的SelectedValueChanged事件获得combobox当前选中的value
如果你的初始化没有改变combobox的SelectedValue,自然就不会触发该事件.
如果仅仅是想在初始化时获取combobox的SelectedValue,可以通过this.comboBox1.SelectedItem.ToString().
但要考虑SelectedItem可能为null

[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;
}
添加事件
private void dataGridView1_EditingControlShowing(object sender, DataGridViewEditingControlShowingEventArgs e)
{
if (e.Control is DataGridViewComboBoxEditingControl)
{
(e.Control as DataGridViewComboBoxEditingControl).SelectedIndexChanged += new EventHandler(DataGridViewComboBoxEditingControl_SelectedIndexChanged);
}
}
private void DataGridViewComboBoxEditingControl_SelectedIndexChanged(object sender, EventArgs e)
{
}

 } 
dataGridView1.Rows[1].Cells[2].ReadOnly = true;
http://www.cnblogs.com/zoupeiyang/archive/2009/07/07/1518174.html