【问题标题】:datagridview1_keypress does not workingdatagridview1 按键不起作用
【发布时间】:2015-07-13 13:09:15
【问题描述】:
        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 没有采取任何行动,这让我很生气。 我太绝望了,任何帮助都会很棒。

【问题讨论】:

  • no keydown 也不起作用。

标签: c# winforms datagridview keypress cell-formatting


【解决方案1】:

问题与以下事实有关:一旦您开始编辑单元格的值,您将不再位于 DataGridView 内,而是位于单元格所属列定义的“编辑控件”内。对于DataGridViewTextBoxColumn,这是TextBox。您需要挂钩编辑控件的事件。详情分享在another answer

【讨论】:

    猜你喜欢
    • 2013-10-10
    • 1970-01-01
    • 2014-09-27
    • 2014-01-18
    • 2013-03-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-02-10
    相关资源
    最近更新 更多