473,466 Members | 1,530 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

How to detect arrow keys?

1 New Member
Hi!

Below is a portion of my program in Visual C#. What I want to do is if arrow keys are pressed nothing will happen. My problem, arrow keys are not detected.

Expand|Select|Wrap|Line Numbers
  1. private void comboBox4_KeyUp(object sender, KeyEventArgs e)
  2.         {
  3.             if (e.KeyCode != Keys.Right || e.KeyCode != Keys.Left || e.KeyCode != Keys.Up || e.KeyCode != Keys.Down)
  4.             {
  5.                 string studname = "^" + comboBox4.Text.ToUpper();
  6.                 connection = new MySqlConnection(connectionstring);
  7.                 int i;
  8.                 int comboitems;
  9.                 //comboBox4.Items.Clear();
  10.                 for (i = 0; i < 100; i++)
  11.                 {
  12.                     student[i] = "";
  13.                 }
  14.                 if (comboBox4.Items.Count != 0)
  15.                 {
  16.                     for (; comboBox4.Items.Count != 0; )
  17.                     {
  18.                         comboBox4.Items.RemoveAt(0);
  19.                     }
  20.                 }
  21.                 //for(i=0;)
  22.                 if (comboBox4.Text.Length > 2)
  23.                 {
  24.                     //textBox1.Text = studname;
  25.                     connection.Open();
  26.                     string section = comboBox1.Text.ToUpper() + " " + comboBox2.Text + " " + comboBox3.Text.ToUpper();
  27.                     string ret1 = "SELECT * FROM `stud_photo` WHERE section='" + section + "' and last_name REGEXP '" + studname + "' ";
  28.                     MySqlCommand retcmd1 = new MySqlCommand(ret1, connection);
  29.                     //MySqlDataReader reader1 = retcmd1.ExecuteReader();
  30.                     //comboBox4.Items.Clear();
  31.                     try
  32.                     {
  33.                         countstud = 0;
  34.                         MySqlDataReader reader1 = retcmd1.ExecuteReader();
  35.                         while (reader1.Read())
  36.                         {
  37.                             student[countstud] = Convert.ToString(reader1["last_name"]);
  38.                             stud_name[countstud] = Convert.ToString(reader1["first_name"]);
  39.                             countstud++;
  40.                         }
  41.  
  42.  
  43.  
  44.                         for (i = 0; i < countstud; i++)
  45.                         {
  46.                             studs[i] = student[i] + ", " + stud_name[i];
  47.                         }
  48.  
  49.                         for (i = 0; i < countstud; i++)
  50.                         {
  51.                             textBox1.Text += studs[i] + "\r\n";
  52.                         }
  53.  
  54.  
  55.                         for (i = 0; i < countstud; i++)
  56.                         {
  57.                             if (comboBox4.FindStringExact(studs[i]) == -1)
  58.                             {
  59.                                 comboBox4.Items.Add(studs[i]);
  60.                             }
  61.  
  62.                         }
  63.                     }
  64.                     catch (MySqlException xc)
  65.                     {
  66.                         //When handling errors, you can use your application's response based 
  67.                         //on the error number.
  68.                         //The two most common error numbers when connecting are as follows:
  69.                         //0: Cannot connect to server.
  70.                         //1045: Invalid user name and/or password.
  71.                         //  switch (ex.Number)
  72.                         //{
  73.                         //  case 0:
  74.                         MessageBox.Show(xc.Message);
  75.                         //    break;
  76.  
  77.                         //case 1045:
  78.                         //MessageBox.Show("Invalid username/password, please try again");
  79.                         //  break;
  80.                         //}
  81.                     }
  82.  
  83.                 }
  84.             }
  85.             /*else
  86.             {
  87.                 MessageBox.Show("Arrow Keys Pressed.");
  88.             }*/
  89.         }
  90.  
Feb 25 '12 #1
1 2911
PsychoCoder
465 Recognized Expert Moderator Contributor
Do you have KeyPreview enabled for form (It's in the forms properties)
Feb 26 '12 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

6
by: Nathan | last post by:
How can I detect when one of the arrow keys is pressed? Thanks, Nathan
4
by: Neil Wallace | last post by:
Hi there, I have an application in which a grid of 100 or more buttons are put on a form in columns of 10. All the buttons are within a panel. They are added in runtime, and so they adopt a...
11
by: Rlrcstr | last post by:
How can you detect when an arrow key gets pressed? Doesn't seem to trigger a KeyPress or KeyDown event. Thanks. Jerry
2
by: Vincent | last post by:
Hi, I have a user control that needs to trap the arrow keys to move items around internally. However, using the arrow keys will move the focus to another control on the form hosting the user...
1
by: Martijn Mulder | last post by:
/* I have problems detecting the Arrow Keys on a User Control. A control derived from System.Windows.Forms.Control neglects 'bare' Arrow Keys but does react on the combination <Altor <Ctrl+ Arrow...
9
by: Laphan | last post by:
Hi All I'm using the below to limit the input into a text box to just letters, numbers, hyphens and full stops, but I also need to allow the backspace, delete and arrow keys to come through. ...
4
by: boopsboops | last post by:
Hi thescripts people, I hope I'm in the right forum for Visual Basic Dotnet (VS 2005). I am trying to make a custom control in which you can nudge a point around using the arrow keys. Actually,...
9
by: Anish G | last post by:
Hi, I have a visual basic application which needs to detect keyboard events. I want to it to detect all the arrow keys (Left, Right, Up, Down) and these should be detected at form level. I have...
2
by: Robert Dufour | last post by:
In Vs 2005 Vb.Net How do you detcet the arrow keys, the function keys, the Ctrl Key, The shift key, the PrintScreen key, scroll lock key NumLock key. I know how to detect the keys that return ascii...
1
by: mecmec | last post by:
i am planning a project to control a toy car by using arrow keys of my computer and by wireless communication. pls help me to get a program to detect only arrow keys and ignore other keystrokes.
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
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...
0
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,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
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...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

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.