C# 2005 WINFORM DataGridView 输入后,回车 如何在回车时得到输入的字符??需高手回答C# 2005 WINFORM DataGridView 我的想法是输入助记码后,回车 选择信息,如何在回车时得到输入的字符。 如在第一列输入 aa回车,怎么得到aa呢?第二列呢? 
protected override bool ProcessCmdKey(ref System.Windows.Forms.Message msg, System.Windows.Forms.Keys keyData) //激活回车键 
        { 
            int WM_KEYDOWN = 256; 
            int WM_SYSKEYDOWN = 260;         
            bool IsDataGridView1 = false; 
            if (this.ActiveControl == this.dMx) 
            { 
                IsDataGridView1 = true; 
            } 
            else 
            { 
                if (this.ActiveControl is IDataGridViewEditingControl) 
                { 
                    if ((this.ActiveControl as IDataGridViewEditingControl).EditingControlDataGridView == this.dMx) 
                    { 
                        IsDataGridView1 = true; 
                    } 
                } 
            }             if (IsDataGridView1) //是否处于DataGridView1 上 
            { 
                if (msg.Msg == WM_KEYDOWN | msg.Msg == WM_SYSKEYDOWN) 
                { 
                    switch (keyData) 
                    { 
                        case Keys.Enter: 
                                if (this.ActiveControl is System.Windows.Forms.DataGridViewComboBoxEditingControl 
                                || this.ActiveControl is System.Windows.Forms.DataGridViewTextBoxEditingControl 
                                ) 
                                { 
                                    if (this.dMx.CurrentCell is DataGridViewTextBoxCell)/ 
                                    { 
                                        if (this.dMx.CurrentCell.ColumnIndex == 0) 
                                        {                                             string str  ; //this.dMx.CurrentCell.Value.ToString(); 
                                            str = this.dMx.Rows[0].Cells[0].Value.ToString(); //怎么得到aa呢?第二列呢? 
//在这里向上面这样写出错,说没有实例化。 
                                        
                                        } 
                                    } 
                                  // SendKeys.Send("{Tab}"); 
                                } 
                            return true; 
                            break; 
                    }                 } 
            } 
            return false; 
        }     }

解决方案 »

  1.   

    我想你要做的是这样的:
    1:响应你需要处理的列的单元格的键盘事件;
    2:设置Handled=true;在单元格内不回显输入字符;
    3:在接收到回车后进行相应的处理;
    4:移动焦点时清空输入的字符序列。
      

  2.   

    你也可以自己写一个自定义的Column比较完美的解决这个问题。
      

  3.   

    自定义Column的代码比较复杂,也不好简单说明。我给你找了一个示例代码,说得还比较清楚。
    http://dev.21tx.com/2006/12/21/10691.html
      

  4.   

    谢谢 PHY 你的示例我看了,没有完整的代码,我不知怎么应用呀。难道没有简单的方法?PB都能做到,C#不能做到?