1 Replies - 413 Views - Last Post: 27 July 2011 - 04:10 AM Rate Topic: -----

#1 metador  Icon User is offline

  • New D.I.C Head

Reputation: -1
  • View blog
  • Posts: 21
  • Joined: 18-June 11

How to control textbox events at same time.

Posted 27 July 2011 - 02:19 AM

hello all,

i have a little logical issue that i have a textbox,when i enter a character in txtbox, keypress event fired first and after that same time textchanged event fired as well.After entering character,autocompletecustomsearch open and when i press down key from keyboad to select text from that customsource,textchanged event was fired first and after that other events fired.I only need that when i press down key,that textchanged event should not be fired.what u suggest.

Is This A Good Question/Topic? 0
  • +

Replies To: How to control textbox events at same time.

#2 morsev  Icon User is offline

  • D.I.C Head

Reputation: -1
  • View blog
  • Posts: 70
  • Joined: 26-September 10

Re: How to control textbox events at same time.

Posted 27 July 2011 - 04:10 AM

Hi my friend you have to put a textbox above combobox and set this codes .
i try it and it's work 100%

public partial class Form1 : Form
    {
        List<string> name = new List<string>();
        int i = 0;
        public Form1()
        {
            InitializeComponent();
            name.Add("samer");
            name.Add("sameer");
            name.Add("somaia");
            name.Add("amjad");
            name.Add("ahmad");
            name.Add("akram");
        }

        private void textBox1_TextChanged(object sender, EventArgs e)
        {
            i = 0;
            comboBox1.DroppedDown = false;
            string partial_name = textBox1.Text;
            comboBox1.Items.Clear();
            foreach (string s in name)
            {
                if (s.StartsWith(partial_name))
                    comboBox1.Items.Add(s);
            }
            comboBox1.DroppedDown = true;
        }

        private void textBox1_KeyDown(object sender, KeyEventArgs e)
        {
            switch (e.KeyCode)
            {
                case Keys.Down:
                    if (i < comboBox1.Items.Count)
                    {
                        i++;
                        comboBox1.SelectedIndex = i - 1;
                    }
                    break;
                case Keys.Up:
                    if (i > 0)
                    {
                        i--;
                        comboBox1.SelectedIndex = i - 1;
                    }
                    break;
                case Keys.Enter:
                    textBox1.Text = comboBox1.Text;
                    comboBox1.DroppedDown = false;
                    break;
                case Keys.Escape:
                    comboBox1.DroppedDown = false;
                    break;
            }
        }
    }


Was This Post Helpful? 0
  • +
  • -

Page 1 of 1