Saurabh Yadav
Saurabh Yadav

Reputation: 1

How to set focus on TextBox (previously the focus was on this TextBox) on KeyPress event of DataGridView

This is my code:

private void gv_old_KeyPress(object sender, KeyPressEventArgs e)
{
    if (e.KeyChar == 27)
    {
        gv_old.Visible = false;
        // And want focus on that TextBox
    }
}

What I want is to focus on the previous TextBox when the focus was on the DataGridView.

Upvotes: 0

Views: 99

Answers (2)

Anonymous Duck
Anonymous Duck

Reputation: 2998

Let just say you have a textbox below :

TextBox textbox1;

You can set focus on the textbox like this,

textbox1.focus();

Upvotes: 1

m_Et
m_Et

Reputation: 46

try this one:

yourTextBox.Focus();

Upvotes: 0

Related Questions