Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Problem with textbox key down and autocomplete

Problem with textbox key down and autocomplete

Scheduled Pinned Locked Moved C#
helpquestion
2 Posts 1 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • G Offline
    G Offline
    GrooverFromHolland
    wrote on last edited by
    #1

    Hi all, I have a textbox with autocomplete set to suggest. I want to execute my code in the Textbox_KeyDown event on the enter key, but enter key is also invoked when I select an item from the text box autocomplete items. That is not what I want. I want the selected item in the textbox and then execute my code. code:

    private void opdrverwTextbox_KeyDown(object sender, KeyEventArgs e)
    {
    if (e.KeyData == (Keys.Enter) && !string.IsNullOrEmpty(opdrverwTextbox.Text))
    {
    //here is the problem. In debugging if I select from dropdown
    // with mouse click: e.KeyData = LButton | MButton | Back
    e.Handled = true;
    a lot of other code........;

            }               
                opdrverwTextbox.Clear();
                opdrverwTextbox.Visible = false;
                opdrverwLabel.Visible = false;
                dataGridView\_Update();
            }           
        }
    

    I don't want to set autocomplete to suggest-append. is there a workaround for this?

    Merry Christmas,

    Groover b>

    0200 A9 23 0202 8D 01 80 0205 00

    G 1 Reply Last reply
    0
    • G GrooverFromHolland

      Hi all, I have a textbox with autocomplete set to suggest. I want to execute my code in the Textbox_KeyDown event on the enter key, but enter key is also invoked when I select an item from the text box autocomplete items. That is not what I want. I want the selected item in the textbox and then execute my code. code:

      private void opdrverwTextbox_KeyDown(object sender, KeyEventArgs e)
      {
      if (e.KeyData == (Keys.Enter) && !string.IsNullOrEmpty(opdrverwTextbox.Text))
      {
      //here is the problem. In debugging if I select from dropdown
      // with mouse click: e.KeyData = LButton | MButton | Back
      e.Handled = true;
      a lot of other code........;

              }               
                  opdrverwTextbox.Clear();
                  opdrverwTextbox.Visible = false;
                  opdrverwLabel.Visible = false;
                  dataGridView\_Update();
              }           
          }
      

      I don't want to set autocomplete to suggest-append. is there a workaround for this?

      Merry Christmas,

      Groover b>

      0200 A9 23 0202 8D 01 80 0205 00

      G Offline
      G Offline
      GrooverFromHolland
      wrote on last edited by
      #2

      Hi all, Found a solution myself after long google search. It works but can someone explain how? here is my new code:

          **\[System.Runtime.InteropServices.DllImport("user32.dll")\]
          private static extern short GetKeyState(Keys key);**
      
          private void opdrverwTextbox\_KeyDown(object sender, KeyEventArgs e)
          {
             
          if (e.KeyData == (Keys.Enter) && !string.IsNullOrEmpty(opdrverwTextbox.Text)**&&             
             GetKeyState(Keys.Enter) < 0)**
              {                
                  e.Handled = true;
                  a lot of other code........;               
              }               
                  opdrverwTextbox.Clear();
                  opdrverwTextbox.Visible = false;
                  opdrverwLabel.Visible = false;
                  dataGridView\_Update();
           }           
      

      Groover,

      0200 A9 23 0202 8D 01 80 0205 00

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups