Forcing Default button on a gridview

后端 未结 2 1973
清歌不尽
清歌不尽 2021-01-06 20:32

I\'m using gridview with templates to show and edit some information from a sql database.

When I edit and change the data in that row and then click enter it automat

2条回答
  •  谎友^
    谎友^ (楼主)
    2021-01-06 20:48

    You need to precess KeyDown or KeyPress event of the grid, and check if pressed key if Keys.Enter :

    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
    
        private void dataGridView1_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Enter)
            {
                button1_Click(this, EventArgs.Empty);
            }
        }
    
        private void button1_Click(object sender, EventArgs e)
        {
            // Your logic here
        }
    }
    

提交回复
热议问题