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. Visual Basic
  4. MessageBox stuck in loop

MessageBox stuck in loop

Scheduled Pinned Locked Moved Visual Basic
helpquestion
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.
  • J Offline
    J Offline
    Joe DiNatale
    wrote on last edited by
    #1

    I have a search dialog form with a text box where the user enters the search terms and a button which executes the search. The text box traps the keyup event so that the user can just press enter and initiate the search instead of clicking on the button. When the search does not return any results, a message box pops up informing the user. The problem is that if the user clears the message box by pressing enter instead of clicking the OK button, the text box gets the keyup event again, performs the search again, puts up the message box... I was able to avoid this by disabling the textbox before showing the message box and then reenabling it after but this moves the focus to the next control. Moving the focus back to the text box (in code) causes the same behavior. Does anyone know of another way to fix this? Joe

    J 1 Reply Last reply
    0
    • J Joe DiNatale

      I have a search dialog form with a text box where the user enters the search terms and a button which executes the search. The text box traps the keyup event so that the user can just press enter and initiate the search instead of clicking on the button. When the search does not return any results, a message box pops up informing the user. The problem is that if the user clears the message box by pressing enter instead of clicking the OK button, the text box gets the keyup event again, performs the search again, puts up the message box... I was able to avoid this by disabling the textbox before showing the message box and then reenabling it after but this moves the focus to the next control. Moving the focus back to the text box (in code) causes the same behavior. Does anyone know of another way to fix this? Joe

      J Offline
      J Offline
      Johan Hakkesteegt
      wrote on last edited by
      #2

      Try to use the textbox's KeyPress event instead of KeyUp: Private Sub TextBox1_KeyPress(ByVal sender As Object, ByVal e As System.EventArgs) Handles TxtFileName_DEV.KeyPress If e.KeyChar = Chr(13) Then If TextBox1.Text = "" then 'Just jump out of the sub so your code does not try to search for nothing exit sub End If 'Reaction when the enter key gets pressed End If End Sub

      My advice is free, and you may get what you paid for.

      J 1 Reply Last reply
      0
      • J Johan Hakkesteegt

        Try to use the textbox's KeyPress event instead of KeyUp: Private Sub TextBox1_KeyPress(ByVal sender As Object, ByVal e As System.EventArgs) Handles TxtFileName_DEV.KeyPress If e.KeyChar = Chr(13) Then If TextBox1.Text = "" then 'Just jump out of the sub so your code does not try to search for nothing exit sub End If 'Reaction when the enter key gets pressed End If End Sub

        My advice is free, and you may get what you paid for.

        J Offline
        J Offline
        Joe DiNatale
        wrote on last edited by
        #3

        Perfect! That did the trick. Thank you very much, Joe

        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