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. Other Discussions
  3. The Weird and The Wonderful
  4. SetFocus to a control that is probably disabled

SetFocus to a control that is probably disabled

Scheduled Pinned Locked Moved The Weird and The Wonderful
7 Posts 6 Posters 2 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.
  • M Offline
    M Offline
    MarcR
    wrote on last edited by
    #1

    Long time ago, in a vb6 application I found this: Private Sub SetFocusControl(ByRef objControl As Control) Dim EnabledControl As Boolean EnabledControl = objControl.Enabled objControl.Enabled = True objControl.SetFocus objControl.Enabled = EnabledControl End Sub :wtf:

    Marc R.

    D N G 3 Replies Last reply
    0
    • M MarcR

      Long time ago, in a vb6 application I found this: Private Sub SetFocusControl(ByRef objControl As Control) Dim EnabledControl As Boolean EnabledControl = objControl.Enabled objControl.Enabled = True objControl.SetFocus objControl.Enabled = EnabledControl End Sub :wtf:

      Marc R.

      D Offline
      D Offline
      Dave Kreskowiak
      wrote on last edited by
      #2

      That person must have come from the Access world where you can't set the focus to a control unless it's Enabled first. IIRC, you couldn't even set the Text of a control unless it had the focus!

      A guide to posting questions on CodeProject[^]
      Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
           2006, 2007

      M 1 Reply Last reply
      0
      • D Dave Kreskowiak

        That person must have come from the Access world where you can't set the focus to a control unless it's Enabled first. IIRC, you couldn't even set the Text of a control unless it had the focus!

        A guide to posting questions on CodeProject[^]
        Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
             2006, 2007

        M Offline
        M Offline
        MarcR
        wrote on last edited by
        #3

        Not at all! He is from c and c++ world...

        Marc R.

        B 1 Reply Last reply
        0
        • M MarcR

          Not at all! He is from c and c++ world...

          Marc R.

          B Offline
          B Offline
          Big Daddy Farang
          wrote on last edited by
          #4

          MarcR. wrote:

          He is from c and c++ world...

          I guess VB6 can do that to the best of us. BDF

          1 Reply Last reply
          0
          • M MarcR

            Long time ago, in a vb6 application I found this: Private Sub SetFocusControl(ByRef objControl As Control) Dim EnabledControl As Boolean EnabledControl = objControl.Enabled objControl.Enabled = True objControl.SetFocus objControl.Enabled = EnabledControl End Sub :wtf:

            Marc R.

            N Offline
            N Offline
            NormDroid
            wrote on last edited by
            #5

            Typical VB code script.

            Follow your nose using DoubleAnimationUsingPath

            1 Reply Last reply
            0
            • M MarcR

              Long time ago, in a vb6 application I found this: Private Sub SetFocusControl(ByRef objControl As Control) Dim EnabledControl As Boolean EnabledControl = objControl.Enabled objControl.Enabled = True objControl.SetFocus objControl.Enabled = EnabledControl End Sub :wtf:

              Marc R.

              G Offline
              G Offline
              Ganesan Sankaran
              wrote on last edited by
              #6

              Hi, I think control must be enabled then only we can set the focus.Because i faced this problem in one of my project. If the control is in diabled then we can't do any operation on it.if you want set focus on the control, it must be enabled as per the code which you written here. otherwise it throws the exception.... Any mistake pls forgive me.

              Thanks and Regards Ganesan.S Software Engineer

              B 1 Reply Last reply
              0
              • G Ganesan Sankaran

                Hi, I think control must be enabled then only we can set the focus.Because i faced this problem in one of my project. If the control is in diabled then we can't do any operation on it.if you want set focus on the control, it must be enabled as per the code which you written here. otherwise it throws the exception.... Any mistake pls forgive me.

                Thanks and Regards Ganesan.S Software Engineer

                B Offline
                B Offline
                BrowniePoints
                wrote on last edited by
                #7

                The question is, why would you want to imperatively set focus on a potentially disabled control? It's like, are you giving a user a listbox that lists all of the controls on the form and when they select one, you set focus to it? I mean I could see how that's useful...like if you have 20 thousand controls on the form. But here's the real question...Why would you want to make a disabled control enabled? Maybe it was a handler for a checkbox and when the user checks the box, it enables a previously disabled control and sets the focus so the user...can...oh wait, it disables the control before the user can do anything.:doh: WTF?:confused:

                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