// 让 dataGridView1 在遇到回车时不响应
protected override bool ProcessCmdKey(ref Message msg, Keys keyData)
{
    if (dataGridView1.Focused || dataGridView1.IsCurrentCellInEditMode)
    {
        if (keyData == Keys.Enter)
        {
            if (dataGridView1.CurrentCellAddress.X == dataGridView1.ColumnCount - 1)
// 让焦点转到下一行或者别的控件 button1.Focus();
else SendKeys.Send("{Right}"); return true; } } return base.ProcessCmdKey(ref msg, keyData); }

 

// 控制输入到 DataGridView 编辑单元格的字符
private void dataGridView1_EditingControlShowing(object sender, DataGridViewEditingControlShowingEventArgs e)
{
    DataGridViewTextBoxEditingControl c = e.Control as DataGridViewTextBoxEditingControl;
    c.KeyPress += c_KeyPress;
}

void c_KeyPress(object sender, KeyPressEventArgs e)
{
    if (e.KeyChar >= 'a' && e.KeyChar <= 'z')
    {
        e.KeyChar = (char)(e.KeyChar - 32);
    }
}

 

相关文章:

  • 2022-12-23
  • 2021-11-27
  • 2021-11-22
  • 2021-06-20
  • 2021-12-23
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2022-02-27
  • 2022-12-23
  • 2022-12-23
  • 2022-01-19
  • 2022-12-23
相关资源
相似解决方案