Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

Combobox enter key press

Posted on 2005-03-15
5
Medium Priority
?
996 Views
Last Modified: 2012-06-21
I feel dumb asking this question....but I won't let that stop me because I want to find out how to do this.

In a C# Windows Form....I have a ComboBox filled with data.  I can PICK an item from the list of items in the ComboBox and that works just fine.

But if I type in the item by hand  (in the combo box text area) and then press ENTER....nothing happens.

What event am I supposed to wire up to the combo box such that an ENTER key press does the same thing as picking an item.

NOTE:  Also...I want to be limited to typin in ONLY valid items that are already listed in the combo box.

NOTE:  The items in the combo box are a list of state abbreviations (WA, UT, WI, NY, etc).
0
Comment
Question by:Tom Knowlton
  • 3
  • 2
5 Comments
 
LVL 5

Author Comment

by:Tom Knowlton
ID: 13546904
Okay..............somehow I missed the KeyDown property..........once I found it I got the ComboBox to work the way I wanted.


I have noticed however.....that every time I press the ENTER key....I get a System Beep that sounds.....WHY??????



private void comboBoxState_SelectedIndexChanged(object sender, System.EventArgs e)
            {
                  try
                  {
                        if ( ! this.comboBoxState.Focused )
                        {
                              return;
                        }
                        else
                        {
                              //get the state
                              string tempState="";
                  
                              tempState = this.comboBoxState.Text;

                              FillAreaCodeBox(tempState);                  
                        }
                  }
                  catch(Exception ee)
                  {
                        System.Diagnostics.Debug.WriteLine(ee.ToString());
                  }
            }

            
            private void comboBoxState_KeyDown(object sender, System.Windows.Forms.KeyEventArgs e)
            {
                  if((e.KeyCode.ToString() == "Enter"))
                  {
                        string tempState = this.comboBoxState.Text;
                        FillAreaCodeBox(tempState);
                  }
            }


            private void FillAreaCodeBox(string tempState)
            {
                  //show all area codes under that state in the Area Codes box
                  string SQL = "select AreaCode from tblAreaCodes where State = '" + tempState + "'";

                  this.listBoxAreaCodes.DataSource = genFuncs.GenerateDataSet(SQL, this.strDBConnection).Tables[0];

                  this.listBoxAreaCodes.DisplayMember = "AreaCode";
                  this.listBoxAreaCodes.ValueMember = "AreaCode";                                                
            }
0
 
LVL 5

Accepted Solution

by:
RoninThe earned 2000 total points
ID: 13547453
hi knowlton,
have you tried setting combobox dropdown style to "DropDownList". I guess that should work.

Ron
0
 
LVL 5

Author Comment

by:Tom Knowlton
ID: 13547473
I tried changing the DropDown list Style to DropDownList.....

This seems to have taken care of it.


=====================================


Now.....I am still curious about why the system DING  when I pressed enter (under the other DropDown style?)
0
 
LVL 5

Expert Comment

by:RoninThe
ID: 13547790
>>Also...I want to be limited to typin in ONLY valid items that are already listed in the combo box.

For this you'll have to set CausesValidation property to true(which is default)

>>Now.....I am still curious about why the system DING  when I pressed enter (under the other DropDown style?)

I don't have the exact answer to this question. When the DropDownStyle is dropdown..no selectionchanged event is fired when you type in the combobox text area..so when you press enter nothing happens..just a DING...
0
 
LVL 5

Author Comment

by:Tom Knowlton
ID: 13547812
>>>>I don't have the exact answer to this question. When the DropDownStyle is dropdown..no selectionchanged event is fired when you type in the combobox text area..so when you press enter nothing happens..just a DING...


Understood.


This is no big deal.....I have the ListBox working how I want it to work now.........


If you do find the answer...please return here and post it.   Just for the sake of curiousity.


Thanks for your help!!!!

Tom
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

We all know that functional code is the leg that any good program stands on when it comes right down to it, however, if your program lacks a good user interface your product may not have the appeal needed to keep your customers happy. This issue can…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
Look below the covers at a subform control , and the form that is inside it. Explore properties and see how easy it is to aggregate, get statistics, and synchronize results for your data. A Microsoft Access subform is used to show relevant calcul…
Is your OST file inaccessible, Need to transfer OST file from one computer to another? Want to convert OST file to PST? If the answer to any of the above question is yes, then look no further. With the help of Stellar OST to PST Converter, you can e…

580 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question