private void Form1_Load(object sender, System.EventArgs e)
{
// this.sqlDataAdapter1 .Fill (this.dataSet11,"shoukuan");
// this.dataGrid1.SetDataBinding (this.dataSet11 ,"shoukuan");
this.oleDbDataAdapter1 .Fill (this.dataSet11 ,"shoukuan");
this.dataGrid1 .RowHeaderWidth =100;
this.dataGrid1 .SetDataBinding (this.dataSet11  ,"shoukuan");
this.dataGrid1 .GridLineStyle =DataGridLineStyle.Solid  ;
this.dataGrid1 .PreferredRowHeight =30;
this.dataGrid1.SelectionBackColor =Color.Beige ;
this.dataGrid1.CaptionText="";
this.dataGrid1.RowHeadersVisible=true; }
private void button1_Click_1(object sender, System.EventArgs e)
{
DataGridTableStyle ts=new DataGridTableStyle ();
ts.MappingName =this.dataSet11 .Tables [0].TableName ;
this.dataGrid1 .TableStyles.Add (ts);
DataGridTextBoxColumn textboxcolumn=(DataGridTextBoxColumn)this.dataGrid1 .TableStyles [0].GridColumnStyles [2];
textboxcolumn.TextBox.KeyPress +=new KeyPressEventHandler(TextBox_KeyPress);
}
private void TextBox_KeyPress(object sender, KeyPressEventArgs e)
{
MessageBox.Show(e.KeyChar.ToString());
}TextBox_KeyPress没有不被触发,执行不了?为什么?谢谢

解决方案 »

  1.   

    Form_Load()
    {
       if ( ! Page.IsPostBack)
       {
        //And DataBinding Code
       }
    }
      

  2.   

    很明显呀,textboxcolumn.TextBox.KeyPress +=new KeyPressEventHandler(TextBox_KeyPress);
    你这句话只是说明textboxcolumn.TextBox的KeyPress发生时执行KeyPressEventHandler(TextBox_KeyPress);,但并没有发生事件KeyPress呀!
      

  3.   

    yzsb1118,你好。
    按键盘不能发生KeyPress事件吗?
    能不能帮我修改一下?