Attaching events to an TextBox underlying for a DataGridView cell

后端 未结 3 721
傲寒
傲寒 2021-01-19 16:28

Is there any way to get underlying control for a DataGridView cell? I would like to attach normal texbox events to capture keystrokes and capture value changed.

So i

3条回答
  •  失恋的感觉
    2021-01-19 17:19

    You can do it with the EditingControlShowing event

    void dataGridView1_EditingControlShowing(object sender, DataGridViewEditingControlShowingEventArgs e)
            {
                if (e.Control is TextBox)
                {
                    (e.Control as TextBox).KeyDown += new KeyEventHandler(Form1_KeyDown);
                    //add as you require
                }
            }
    
            void Form1_KeyDown(object sender, KeyEventArgs e)
            {
                // your code here
            }
    

提交回复
热议问题