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. WCF and WF
  4. could not capture down arrow in combobox in wpf

could not capture down arrow in combobox in wpf

Scheduled Pinned Locked Moved WCF and WF
csharpwpfhelp
3 Posts 2 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.
  • D Offline
    D Offline
    dashingsidds
    wrote on last edited by
    #1

    Hi Experts, I have a combobox on a window in wpf and i am trying to capture the down arrow key of this combobox but i am not able to do so. The following is the only code i have for the combobox.

    <ComboBox Height="23" HorizontalAlignment="Left" Margin="10,10,0,0" Name="comboBox1" VerticalAlignment="Top" Width="120"
    PreviewKeyDown="comboBox1_PreviewKeyDown" KeyDown="comboBox1_KeyDown" IsEditable="True"/>

    C#

    private void comboBox1\_PreviewKeyDown(object sender, KeyEventArgs e)
        {
            if (e.Key == Key.Down)
                MessageBox.Show("hi");
        }
    
        private void comboBox1\_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.Key == Key.Down)
                MessageBox.Show("hi");
        }
    

    The event is not even hit when i press down arrow key. Please help! Thanks in advance! Regards, Samar

    D A 2 Replies Last reply
    0
    • D dashingsidds

      Hi Experts, I have a combobox on a window in wpf and i am trying to capture the down arrow key of this combobox but i am not able to do so. The following is the only code i have for the combobox.

      <ComboBox Height="23" HorizontalAlignment="Left" Margin="10,10,0,0" Name="comboBox1" VerticalAlignment="Top" Width="120"
      PreviewKeyDown="comboBox1_PreviewKeyDown" KeyDown="comboBox1_KeyDown" IsEditable="True"/>

      C#

      private void comboBox1\_PreviewKeyDown(object sender, KeyEventArgs e)
          {
              if (e.Key == Key.Down)
                  MessageBox.Show("hi");
          }
      
          private void comboBox1\_KeyDown(object sender, KeyEventArgs e)
          {
              if (e.Key == Key.Down)
                  MessageBox.Show("hi");
          }
      

      The event is not even hit when i press down arrow key. Please help! Thanks in advance! Regards, Samar

      D Offline
      D Offline
      dashingsidds
      wrote on last edited by
      #2

      Hi Guys, I got the answer. The PreviewKeyUp event worked for the down arrow. Thanks anyways for looking into it for me. But can anyone please explain as to y the PreviewKeyDown event did not get fired for down arrow?? Regards, Dhaval

      1 Reply Last reply
      0
      • D dashingsidds

        Hi Experts, I have a combobox on a window in wpf and i am trying to capture the down arrow key of this combobox but i am not able to do so. The following is the only code i have for the combobox.

        <ComboBox Height="23" HorizontalAlignment="Left" Margin="10,10,0,0" Name="comboBox1" VerticalAlignment="Top" Width="120"
        PreviewKeyDown="comboBox1_PreviewKeyDown" KeyDown="comboBox1_KeyDown" IsEditable="True"/>

        C#

        private void comboBox1\_PreviewKeyDown(object sender, KeyEventArgs e)
            {
                if (e.Key == Key.Down)
                    MessageBox.Show("hi");
            }
        
            private void comboBox1\_KeyDown(object sender, KeyEventArgs e)
            {
                if (e.Key == Key.Down)
                    MessageBox.Show("hi");
            }
        

        The event is not even hit when i press down arrow key. Please help! Thanks in advance! Regards, Samar

        A Offline
        A Offline
        Abhinav S
        wrote on last edited by
        #3

        Subclassing your combobox could have been an alternate - see here[^]. This also explains why you could not get anything in KeyDown.

        The funniest thing about this particular signature is that by the time you realise it doesn't say anything it's too late to stop reading it. My latest tip/trick Visit the Hindi forum here.

        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