Yes it is possible! You could consume the "KeyUp" event of the ComboBox for
doing this:
--------------------------------------------------------------------------------------------
The code below gives you a clear picture of the sequence in which the
relevant events are triggered.
public Form1()
{
//
// Required for Windows Form Designer support
//
InitializeCompo nent();
//
// TODO: Add any constructor code after InitializeCompo nent call
this.comboBox1. SelectionChange Committed +=new
EventHandler(co mboBox1_Selecti onChangeCommitt ed);
this.comboBox1. KeyDown +=new KeyEventHandler (comboBox1_KeyD own);
this.comboBox1. KeyUp +=new KeyEventHandler (comboBox1_KeyU p);
//
}
static void Main()
{
Application.Run (new Form1());
}
private void Form1_Load(obje ct sender, System.EventArg s e)
{
comboBox1.Items .Add("A");
comboBox1.Items .Add("B");
comboBox1.Items .Add("C");
comboBox1.Items .Add("D");
comboBox1.Items .Add("E");
}
private void comboBox1_Selec tionChangeCommi tted(object sender, EventArgs
e)
{
Debug.WriteLine (this.comboBox1 .SelectedItem);
}
private void comboBox1_KeyDo wn(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.Enter)
{
Debug.WriteLine ("ENTER KEY DOWN");
}
}
private void comboBox1_KeyUp (object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.Enter)
{
Debug.WriteLine ("ENTER KEY UP");
/*Do your DB Re-Query operation here as this gets triggered after the
SelectChangeCom mitted event...*/
}
}
Hope this helps!
Thanks-
"Rotsey" <ma***********@ RemoveThis.optu snet.com.auwrot e in message
news:%2******** ************@TK 2MSFTNGP05.phx. gbl...
what I have is a form that displays data from db and a filter
on employee name combo
I want to be able to arrow key through the list and then hit enter when
I find the employee and then only requery the form on enter
is this possible and how?
"Shine Xavier" <sh**********@g mail.comwrote in message
news:%2******** **********@TK2M SFTNGP06.phx.gb l...
>Hi,
You are automatically selecting the items as you navigate using the Arrow
keys. So hitting the Enter key doesn't have any speciifc relevance as the
item would already have been selected by the time you hit the Enter key.
Please see the code below which demonstrates this:
public Form1()
{
//
// Required for Windows Form Designer support
//
InitializeCompo nent();
//
// TODO: Add any constructor code after InitializeCompo nent call
this.comboBox1. SelectedIndexCh anged +=new
EventHandler(c omboBox1_Select edIndexChanged) ;
//
}
static void Main()
{
Application.Run (new Form1());
}
private void Form1_Load(obje ct sender, System.EventArg s e)
{
comboBox1.Items .Add("A");
comboBox1.Items .Add("B");
comboBox1.Items .Add("C");
comboBox1.Items .Add("D");
comboBox1.Items .Add("E");
}
private void comboBox1_Selec tedIndexChanged (object sender, EventArgs e)
{
Debug.WriteLine (this.comboBox1 .SelectedItem);
}
Hope this helps!
Thanks -
"Rotsey" <ma***********@ RemoveThis.optu snet.com.auwrot e in message
news:et******* ******@TK2MSFTN GP06.phx.gbl...
>>Hi,
I am having a problem trying to select an item with the enter key.
I want to work the combo with the keyboard.
So when I use the down arrow to browse the list I want to then
hit the enter key as if selecting an item with the mouse.
How do I do this?
Can't seem to get it working.
Is this a setup of the combo issue?
rotsey