datagridview1_keypress不起作用

时间:2015-07-13 13:09:16

标签: c# winforms datagridview keypress cell-formatting

        private void dataGridView1_KeyPress(object sender, KeyPressEventArgs e)
    {
        if (dataGridView1.CurrentCell.ColumnIndex == 5 || dataGridView1.CurrentCell.ColumnIndex == 10)
        {
            aTimer.Interval = 850;
            aTimer.Start();
            string pwd = "*";
            pass.Add(e.KeyChar);
            dataGridView1.CurrentCell.Value = pwd;
            dataGridView1.CurrentCell.Value = GridView1_PreRender1(dataGridView1.CurrentCell.Value.ToString());

        }
    }

我没有得到任何错误但是在运行时我点击并输入值网格单元格KeyPress不采取任何行动并且它会杀了我。 我太绝望了,任何帮助都会很棒。

1 个答案:

答案 0 :(得分:1)

问题与以下事实有关:一旦您开始编辑单元格的值,您就不再在DataGridView范围内,而是在单元格拥有列定义的“编辑控件”中。对于DataGridViewTextBoxColumn,这是TextBox。您需要挂钩编辑控件的事件。其详细信息在another answer中分享: