DataGridView ImageColumn句柄“Enter”执行点击 [英] DataGridView ImageColumn Handle "Enter" key to perform Click

查看:133
本文介绍了DataGridView ImageColumn句柄“Enter”执行点击的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果点击 c code code> DataGridViewImageColumn ,当我按输入。目前,当我在 DataGridViewImageColumn 上按输入键时,会移动到下一个单元格。

How to fire Click event of DataGridViewImageColumn when I press Enter. Currently when I press the Enter key on DataGridViewImageColumn it moves to next cell.

请帮助。

推荐答案

您可以在方法中将要运行的代码放在 CellContentClick 中,然后在 CellContentClick KeyDown 中调用该方法。

You can put the code that you want to run in CellContentClick in a method and then on both CellContentClick and KeyDown call that method.

private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
{
    if (e.RowIndex >= 0 && e.ColumnIndex== 3)
        DoSomething(e.RowIndex, e.ColumnIndex);
}

public void DoSomething(int row, int column)
{
    MessageBox.Show(string.Format("Cell({0},{1}) Clicked", row, column));
}

private void dataGridView1_KeyDown(object sender, KeyEventArgs e)
{
    var cell = this.dataGridView1.CurrentCell;
    if (cell != null && e.KeyCode == Keys.Enter &&
        cell.RowIndex >= 0 && cell.ColumnIndex == 3)
    {
        DoSomething(cell.RowIndex, cell.ColumnIndex);
        e.Handled = true;
    }
}

这篇关于DataGridView ImageColumn句柄“Enter”执行点击的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆