TextCol .TextBox.KeyPress += new System.Windows.Forms.KeyPressEventHandler(TextBox_KeyPress);
对datagride中添加新列TextBox的KeyPress事件却没有响应,也没有任何错误!请教!!!!!!!!!!!!!!!!

解决方案 »

  1.   

    TextCol.TextBox 是什么意思.
    textBox1.KeyPress+= new System.Windows.Forms.KeyPressEventHandler(TextBox_KeyPress);
    private void TextBox_KeyPress(object sender, System.Windows.Forms.KeyPressEventArgs e)
    {
    MessageBox.Show("!!");
    }没事问题.可以相应
      

  2.   

    lz: 
       问题出在“对datagride中添加新列TextBox”,KeyDown ,KeyPress 这类事件响应有个前提:在控件有焦点的情况下!!在单独的TextBox控件里没有问题, 而datagrid网格控件不会响应,你用CellLeave(单元格事件)做处理即可。
      

  3.   

    如果textbox是在datagrid中的模板列,需要在绑定datagrid时动态声明事件