0
I created a program that has the Client Search field that loads the Clients in listview.. I want to search by filling in the Textbox and Pressing the Enter Key
0
I created a program that has the Client Search field that loads the Clients in listview.. I want to search by filling in the Textbox and Pressing the Enter Key
4
You can use the event KeyDown
.
Instead of using the key code, make use of the enumeration of keys.
private void textBox1_KeyUp(object sender, KeyEventArgs e) {
if (e.KeyCode == Keys.Enter)
ExecutarBusca();
}
Alternative - make use of the property AcceptButton
.
The button that is assigned to this property will be executed automatically by pressing the Enter key.
By code:
private void Form1_Load(object sender, EventArgs e) {
this.AcceptButton = btnPesquisar;
}
Or by the interface:
0
private void SetDefault(Button myDefaultBtn)
{
this.AcceptButton = myDefaultBtn;
}
0
use the textbox Keypress event
private void textBox1_KeyPress(object sender, KeyPressEventArgs e)
{
if (e.KeyChar == 13)
{
//Executa a pesquisa
}
}
another option, which I use, is Textchanged next to a timer, which the search is done automatically when filling the textbox:
private void textBox1_TextChanged(object sender, EventArgs e)
{
timerPesquisa.Enabled = false;
timerPesquisa.Enabled = true;
}
private void timerPesquisa_Tick(object sender, EventArgs e)
{
timerPesquisa.Enabled = false;
//Executa a pesquisa
}
-2
private void textBox1_KeyPress(Object Sender, Keypresseventargs and) { if (e.Keychar == 13) { btnPsearch.Performclick(); //it will simulate a click on the button. } }
Browser other questions tagged c# winforms
You are not signed in. Login or sign up in order to post.
Adding an action(or Listener, I don’t know what it’s called in c#) on the component to monitor when the button is pressed?
– user28595
EventHandler
, @diegofm. But the common term is Istener himself.– Jéf Bueno
Like a google search... type in the field and hit Enter.. No need to click with the mouse or Tab to select the button
– Gilberto Lira da Cruz
solved your problem ?
– Rovann Linhalis