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 I can't get past.

Problem I can't get past.

Scheduled Pinned Locked Moved C#
help
6 Posts 3 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.
  • C Offline
    C Offline
    Cory Borrow
    wrote on last edited by
    #1

    I have an application it is tabbed based and holds a texteditor in each tab (The ICSharpCode TextEditorControl). I can open as many tabs as I want but when I switch bewteen 2 or three tabs I get this error. I'm am getting "Object reference not set to an instance of an object" result back. Problay somthing small I am missing somewhere, but I can't see where. Below is the code for when a tab switches. void TabControl1SelectedIndexChanged(object sender, EventArgs e) { if(tabControl1.TabPages.Count > 0 && !tabControl1.SelectedTab.Disposing) { openFile = tabControl1.SelectedTab.ToolTipText; if(lengthSet == false) { if(oldLength != tabControl1.SelectedTab.Controls["textEditorControl1"].Text.Length) oldLength = tabControl1.SelectedTab.Controls["textEditorControl1"].Text.Length; if((bool)tabControl1.SelectedTab.Tag == true) { saveToolStripMenuItem.Enabled = false; toolStripButton3.Enabled = false; } else { saveToolStripMenuItem.Enabled = true; toolStripButton3.Enabled = true; } } } lengthSet = false; } The Line if((bool)tabControl.SelectedTab.Tag == true) returns the error If I add TextEditorControl editor = (TextEditorControl)tabControl1.SelectedTab.Controls["textEditorControl1"]; and replace the line with the error with if(editor.IsReadOnly) It still returns the same thing.

    E C 2 Replies Last reply
    0
    • C Cory Borrow

      I have an application it is tabbed based and holds a texteditor in each tab (The ICSharpCode TextEditorControl). I can open as many tabs as I want but when I switch bewteen 2 or three tabs I get this error. I'm am getting "Object reference not set to an instance of an object" result back. Problay somthing small I am missing somewhere, but I can't see where. Below is the code for when a tab switches. void TabControl1SelectedIndexChanged(object sender, EventArgs e) { if(tabControl1.TabPages.Count > 0 && !tabControl1.SelectedTab.Disposing) { openFile = tabControl1.SelectedTab.ToolTipText; if(lengthSet == false) { if(oldLength != tabControl1.SelectedTab.Controls["textEditorControl1"].Text.Length) oldLength = tabControl1.SelectedTab.Controls["textEditorControl1"].Text.Length; if((bool)tabControl1.SelectedTab.Tag == true) { saveToolStripMenuItem.Enabled = false; toolStripButton3.Enabled = false; } else { saveToolStripMenuItem.Enabled = true; toolStripButton3.Enabled = true; } } } lengthSet = false; } The Line if((bool)tabControl.SelectedTab.Tag == true) returns the error If I add TextEditorControl editor = (TextEditorControl)tabControl1.SelectedTab.Controls["textEditorControl1"]; and replace the line with the error with if(editor.IsReadOnly) It still returns the same thing.

      E Offline
      E Offline
      Ed Poore
      wrote on last edited by
      #2

      Any chance that the SelectedTab is null when this exception is thrown?  Check it with the debugger.


      My Blog

      C 1 Reply Last reply
      0
      • E Ed Poore

        Any chance that the SelectedTab is null when this exception is thrown?  Check it with the debugger.


        My Blog

        C Offline
        C Offline
        Cory Borrow
        wrote on last edited by
        #3

        It shows that it selected has a TabPage I can view all the info for that tabpage and everything though the debugger. It's weird that it stops and that line though, it skips the rest of the places where I have used tabControl1.SelectedTab.

        1 Reply Last reply
        0
        • C Cory Borrow

          I have an application it is tabbed based and holds a texteditor in each tab (The ICSharpCode TextEditorControl). I can open as many tabs as I want but when I switch bewteen 2 or three tabs I get this error. I'm am getting "Object reference not set to an instance of an object" result back. Problay somthing small I am missing somewhere, but I can't see where. Below is the code for when a tab switches. void TabControl1SelectedIndexChanged(object sender, EventArgs e) { if(tabControl1.TabPages.Count > 0 && !tabControl1.SelectedTab.Disposing) { openFile = tabControl1.SelectedTab.ToolTipText; if(lengthSet == false) { if(oldLength != tabControl1.SelectedTab.Controls["textEditorControl1"].Text.Length) oldLength = tabControl1.SelectedTab.Controls["textEditorControl1"].Text.Length; if((bool)tabControl1.SelectedTab.Tag == true) { saveToolStripMenuItem.Enabled = false; toolStripButton3.Enabled = false; } else { saveToolStripMenuItem.Enabled = true; toolStripButton3.Enabled = true; } } } lengthSet = false; } The Line if((bool)tabControl.SelectedTab.Tag == true) returns the error If I add TextEditorControl editor = (TextEditorControl)tabControl1.SelectedTab.Controls["textEditorControl1"]; and replace the line with the error with if(editor.IsReadOnly) It still returns the same thing.

          C Offline
          C Offline
          Christian Graus
          wrote on last edited by
          #4

          SelectedTab must be null, unless tabControl is. That's the only explanation for the error. Assuming the error is not thrown by the cast, and the Tag might be null ?

          Christian Graus - Microsoft MVP - C++ "I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )

          C 1 Reply Last reply
          0
          • C Christian Graus

            SelectedTab must be null, unless tabControl is. That's the only explanation for the error. Assuming the error is not thrown by the cast, and the Tag might be null ?

            Christian Graus - Microsoft MVP - C++ "I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )

            C Offline
            C Offline
            Cory Borrow
            wrote on last edited by
            #5

            Thanks, I checked out the debugging info and saw that Tag was not even showing up in it, so I created another class to extend the TabPage and added an IsFileReadOnly variable and it seems to work fine now.

            C 1 Reply Last reply
            0
            • C Cory Borrow

              Thanks, I checked out the debugging info and saw that Tag was not even showing up in it, so I created another class to extend the TabPage and added an IsFileReadOnly variable and it seems to work fine now.

              C Offline
              C Offline
              Christian Graus
              wrote on last edited by
              #6

              Great - that exception always means something is null, I didn't realise it would be thrown by the cast attempt, that occured to me at the last minute. I'd always use the Convert. or a TryParse ( bool.TryParse ? ) to do conversions, and check for null first.

              Christian Graus - Microsoft MVP - C++ "I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )

              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