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
- private void comboBox4_KeyUp(object sender, KeyEventArgs e)
- {
- if (e.KeyCode != Keys.Right || e.KeyCode != Keys.Left || e.KeyCode != Keys.Up || e.KeyCode != Keys.Down)
- {
- string studname = "^" + comboBox4.Text.ToUpper();
- connection = new MySqlConnection(connectionstring);
- int i;
- int comboitems;
- //comboBox4.Items.Clear();
- for (i = 0; i < 100; i++)
- {
- student[i] = "";
- }
- if (comboBox4.Items.Count != 0)
- {
- for (; comboBox4.Items.Count != 0; )
- {
- comboBox4.Items.RemoveAt(0);
- }
- }
- //for(i=0;)
- if (comboBox4.Text.Length > 2)
- {
- //textBox1.Text = studname;
- connection.Open();
- string section = comboBox1.Text.ToUpper() + " " + comboBox2.Text + " " + comboBox3.Text.ToUpper();
- string ret1 = "SELECT * FROM `stud_photo` WHERE section='" + section + "' and last_name REGEXP '" + studname + "' ";
- MySqlCommand retcmd1 = new MySqlCommand(ret1, connection);
- //MySqlDataReader reader1 = retcmd1.ExecuteReader();
- //comboBox4.Items.Clear();
- try
- {
- countstud = 0;
- MySqlDataReader reader1 = retcmd1.ExecuteReader();
- while (reader1.Read())
- {
- student[countstud] = Convert.ToString(reader1["last_name"]);
- stud_name[countstud] = Convert.ToString(reader1["first_name"]);
- countstud++;
- }
- for (i = 0; i < countstud; i++)
- {
- studs[i] = student[i] + ", " + stud_name[i];
- }
- for (i = 0; i < countstud; i++)
- {
- textBox1.Text += studs[i] + "\r\n";
- }
- for (i = 0; i < countstud; i++)
- {
- if (comboBox4.FindStringExact(studs[i]) == -1)
- {
- comboBox4.Items.Add(studs[i]);
- }
- }
- }
- catch (MySqlException xc)
- {
- //When handling errors, you can use your application's response based
- //on the error number.
- //The two most common error numbers when connecting are as follows:
- //0: Cannot connect to server.
- //1045: Invalid user name and/or password.
- // switch (ex.Number)
- //{
- // case 0:
- MessageBox.Show(xc.Message);
- // break;
- //case 1045:
- //MessageBox.Show("Invalid username/password, please try again");
- // break;
- //}
- }
- }
- }
- /*else
- {
- MessageBox.Show("Arrow Keys Pressed.");
- }*/
- }