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. disabling a textbox at intialization in wpf/C#

disabling a textbox at intialization in wpf/C#

Scheduled Pinned Locked Moved C#
csharpwpfhelpquestion
4 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
    jhoga
    wrote on last edited by
    #1

    I'm stumped I have two programs. I'm using the same code in both. It works in one and not in the other. Anybody have any idea what could be causing this? error: System.NullReferenceException: 'Object reference not set to an instance of an object.' tbQ2 was null. code:

    private void Btn1_Checked(object sender, RoutedEventArgs e)
    {

            Qtype = "LIKE";
            Qpre = " '";
            Qpost = "%'";
            tbQ2.IsEnabled = false;
        }
    

    THE XAML code for the wpf is.

    And:

    L 1 Reply Last reply
    0
    • J jhoga

      I'm stumped I have two programs. I'm using the same code in both. It works in one and not in the other. Anybody have any idea what could be causing this? error: System.NullReferenceException: 'Object reference not set to an instance of an object.' tbQ2 was null. code:

      private void Btn1_Checked(object sender, RoutedEventArgs e)
      {

              Qtype = "LIKE";
              Qpre = " '";
              Qpost = "%'";
              tbQ2.IsEnabled = false;
          }
      

      THE XAML code for the wpf is.

      And:

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2

      jhoga wrote:

      Object reference not set to an instance of an object...

      ... is one of the most common questions asked here. It merely means that you are using a variable reference that has not been initialised, either through omission or error. The only way to track it down is by using the debugger to examine all references at the point of failure. In your case the offending variable is tbQ2, but we cannot guess where it should have been setup, or what other code may have affected it.

      J 1 Reply Last reply
      0
      • L Lost User

        jhoga wrote:

        Object reference not set to an instance of an object...

        ... is one of the most common questions asked here. It merely means that you are using a variable reference that has not been initialised, either through omission or error. The only way to track it down is by using the debugger to examine all references at the point of failure. In your case the offending variable is tbQ2, but we cannot guess where it should have been setup, or what other code may have affected it.

        J Offline
        J Offline
        jhoga
        wrote on last edited by
        #3

        I guess I should have been more detailed in explaining the issue. The code in the two programs are almost identical. I have used this report writer wpf window many times and never had this issue. The xaml code for the checkbox is apparently setting the text box before it is getting initialized in wpf. "OOPs" I think I might have just answered my on question. I hate when that happens. :)

        J 1 Reply Last reply
        0
        • J jhoga

          I guess I should have been more detailed in explaining the issue. The code in the two programs are almost identical. I have used this report writer wpf window many times and never had this issue. The xaml code for the checkbox is apparently setting the text box before it is getting initialized in wpf. "OOPs" I think I might have just answered my on question. I hate when that happens. :)

          J Offline
          J Offline
          jhoga
          wrote on last edited by
          #4

          Yep, I moved where the text box was in the wpf stack and all is right with the world. :)

          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