473,586 Members | 2,491 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Select an item in a combo box with enter key

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
Jun 26 '07 #1
7 10326
Hi Rotsey,

Winfoms I guess?
If yes then why do you need to select it by Enter if on keyboard-mode SelectedIndexCh anged
is called by any cursor movement?

Kind Regards, Alex Meleta
[TechBlog] http://devkids.blogspot.com

RHi,
R>
RI am having a problem trying to select an item with the enter key.
R>
RI want to work the combo with the keyboard.
R>
RSo when I use the down arrow to browse the list I want to then hit
Rthe enter key as if selecting an item with the mouse.
R>
RHow do I do this?
R>
RCan't seem to get it working.
R>
RIs this a setup of the combo issue?
R>
Rrotsey
R>
Jun 26 '07 #2
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(co mboBox1_Selecte dIndexChanged);
//
}

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******** *****@TK2MSFTNG P06.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

Jun 26 '07 #3
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(co mboBox1_Selecte dIndexChanged);
//
}

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******** *****@TK2MSFTNG P06.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


Jun 26 '07 #4
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



Jun 26 '07 #5
Hi,

"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?
Yes, It's possible

You have to use Form.ProcessCmd Key.

Jun 26 '07 #6
Ok thanks I will give it ago

"Shine Xavier" <sh**********@g mail.comwrote in message
news:OR******** *****@TK2MSFTNG P06.phx.gbl...
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******* ***********@TK2 MSFTNGP06.phx.g bl...
>>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( comboBox1_Selec tedIndexChanged );
//
}

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****** *******@TK2MSFT NGP06.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



Jun 26 '07 #7
On Tue, 26 Jun 2007 06:48:06 -0700, Ignacio Machin ( .NET/ C# MVP )
<machin TA <"laceupsolutio ns.com>"wrote:
>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?

Yes, It's possible

You have to use Form.ProcessCmd Key.
I disagree on at least two counts: 1) there are other ways to do it, and
2) Control.Process CmdKey() isn't even the best way to do it.

Personally, I'd sub-class the control and override the
Control.Process DialogKey() method.

ProcessCmdKey() is more commonly used for keyboard accelerator shortcuts
(Alt-<key>, Ctrl-<key>, etc.) while ProcessDialogKe y() is intended for
situations in which a modifier key isn't relevant. As also has been
pointed out, one can subscribe to the KeyUp or KeyDown events (I prefer
KeyDown, because you will get one for each key repeat, but sometimes you
don't want to handle key repeats in which case KeyUp is preferable). You
can even subscribe to KeyPress if what you care about is the character
code generated rather than a specific key.

Not that you can't do it using ProcessCmdKey() ...I just feel that there
are other, more appropriate methods.

Pete
Jun 26 '07 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
8834
by: mr_burns | last post by:
hi, using javascript, how do i select an option in a combo box? i have tried looking on the internet but dont really know what i should be searching for. what i want to happen is that when a function is called a line of code will select a specific option in a combo box. something like: //excuse the dodgy syntax
14
2921
by: Jos? | last post by:
This one droves me completely mad. I did not succeed to exploit the track given to me by Bob. I have : three tables : Clubs, Persons and ClubsPersons that join the two first in a many to many relationship. Club has two (2) fields : ClubId (Autonumber) and ClubName (Text). Peoples has two(2) fields : (PersonId (Autonumber) and PersonName...
6
3415
by: Robin S. | last post by:
Originally I wanted a list box which selects which record is the current one within the same form. Easy enough until Access takes a dump when one is deleted and then someone tries to select it in the list box (same session). I can't get the repaint to work at all. So, what about a pop-up that shows a list box. The user selects which record...
3
2077
by: Cillies | last post by:
Hi all, I was wondering if anyone knows how to manipulate combo boxes. What I want to do is as follows: - Two combo boxes 1st box contains = Interested, Not Interested 2nd box contains = Renewal, Upgrade, new
5
3686
by: jjyconsulting | last post by:
Newbie needing some help. I have a tblParticipants. The fields include gender, education_level, income, occupation etc., I'm trying to create a form where a user can run a query from the form and just choose the appropriate criterias from the combo boxes to get the results. I also want the query to run even if there is not a value in all...
1
2888
by: swapna.munukoti | last post by:
Hi all, Is there a way to display some text in html select control by default which when the control is clicked, will not be listed in the drop down that contains its options. For example: When I open a page, there is a combo box with "Select" displayed in that. It looks like that item is selected. But when I click that combo box, it...
4
3109
by: mistyblu | last post by:
I wrote an Access97 application using VBA for a company many moons ago and they have approximately 20 users. All has been hunky dory for a long time but suddenly they have a combo box error on 3 of the pc's. The identical application works fine on the other 17 pc's. The O/S is Windows XP Pro service pack 2. There are several combo boxes on...
4
11161
by: Kai12 | last post by:
Hello I am trying to create a combo box that would display data from a dataset, and also a 'Please Select' as the first item. I have written the following code which derives from a combo box and it works fine in visual studio 2003 but in 2008 would not display the comboboxtext (which is 'Please select'). any one has any ideas what i have done...
0
7841
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
8204
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
8220
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6617
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5712
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
3838
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3869
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1452
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
1184
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.