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. Object disposed when trying to assign column width

Object disposed when trying to assign column width

Scheduled Pinned Locked Moved Visual Basic
helpdebuggingdatabasequestion
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.
  • H Offline
    H Offline
    Hypermommy
    wrote on last edited by
    #1

    Hi all, I have a datagridview on a form. I have a subroutine called LoadReloadProcs that has this line in it Me.dgvProcs.Columns(0).Width = Me.dgvProcs.Width * 0.75 This is the line where the error's happening. I'm getting an objectdisposed error. Funny thing is, it'll run through this routine twice without reporting an error. It only reports the error when I come back from running a report. Also, if I put a breakpoint right there and use the immediate window to check the value of the width (i.e., ? dgvProcs.Columns(0).Width) the system tells me that it is 100. But if I try to assign a value to the width (i.e., in the immediate window dgvProcs.Columns(0).Width = 435) the system throws the object disposed error. Why would I be able to request information of an object that is disposed? I shouldn't be able to, right? Or if it is not disposed, which being able to query the value of something suggests, why can't I assign a value to that property? This has me really confused. I've put the code for the procedure below... I don't see anything in there that helps me understand, but I figured one of y'all might. Also, I've searched for "dgvProcs.dispose" and just for ".dispose" and didn't find any relevant to dgvProcs.

    Private Sub LoadReloadProcList(ByVal strsql As String)
    Try
    'Me.Controls.Remove(dgvProcs)
    Dim daMyList = New SqlCeDataAdapter(strsql, myDB.cn)
    Dim dsMyList = New DataSet
    daMyList.Fill(dsMyList)
    Dim myBinding As New BindingSource
    myBinding.DataSource = dsMyList
    Me.dgvProcs.DataSource = myBinding
    Me.dgvProcs.DataMember = "Table"
    Me.dgvProcs.Columns(0).HeaderText = "Name"
    Me.dgvProcs.Columns(0).Width = Me.dgvProcs.Width * 0.75
    Me.dgvProcs.Columns(1).HeaderText = "Barcode"
    Me.dgvProcs.Columns(1).Width = Me.dgvProcs.Width * 0.15
    Me.Controls.Add(dgvProcs)
    Catch ex As Exception
    #If DEBUG Then
    MsgBox(ex.Message)
    #Else
    MsgBox("There was a problem gathering information on your previous procedures. If this problem persists please contact your distributor.")
    #End If
    End Try
    End Sub

    Thanks in advance for any help you can give.

    Denise "Hypermommy" Duggan

    D 1 Reply Last reply
    0
    • H Hypermommy

      Hi all, I have a datagridview on a form. I have a subroutine called LoadReloadProcs that has this line in it Me.dgvProcs.Columns(0).Width = Me.dgvProcs.Width * 0.75 This is the line where the error's happening. I'm getting an objectdisposed error. Funny thing is, it'll run through this routine twice without reporting an error. It only reports the error when I come back from running a report. Also, if I put a breakpoint right there and use the immediate window to check the value of the width (i.e., ? dgvProcs.Columns(0).Width) the system tells me that it is 100. But if I try to assign a value to the width (i.e., in the immediate window dgvProcs.Columns(0).Width = 435) the system throws the object disposed error. Why would I be able to request information of an object that is disposed? I shouldn't be able to, right? Or if it is not disposed, which being able to query the value of something suggests, why can't I assign a value to that property? This has me really confused. I've put the code for the procedure below... I don't see anything in there that helps me understand, but I figured one of y'all might. Also, I've searched for "dgvProcs.dispose" and just for ".dispose" and didn't find any relevant to dgvProcs.

      Private Sub LoadReloadProcList(ByVal strsql As String)
      Try
      'Me.Controls.Remove(dgvProcs)
      Dim daMyList = New SqlCeDataAdapter(strsql, myDB.cn)
      Dim dsMyList = New DataSet
      daMyList.Fill(dsMyList)
      Dim myBinding As New BindingSource
      myBinding.DataSource = dsMyList
      Me.dgvProcs.DataSource = myBinding
      Me.dgvProcs.DataMember = "Table"
      Me.dgvProcs.Columns(0).HeaderText = "Name"
      Me.dgvProcs.Columns(0).Width = Me.dgvProcs.Width * 0.75
      Me.dgvProcs.Columns(1).HeaderText = "Barcode"
      Me.dgvProcs.Columns(1).Width = Me.dgvProcs.Width * 0.15
      Me.Controls.Add(dgvProcs)
      Catch ex As Exception
      #If DEBUG Then
      MsgBox(ex.Message)
      #Else
      MsgBox("There was a problem gathering information on your previous procedures. If this problem persists please contact your distributor.")
      #End If
      End Try
      End Sub

      Thanks in advance for any help you can give.

      Denise "Hypermommy" Duggan

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

      You have a DataGridView on your form that YOU called dgvProcs. So, obviously searching the Internet for a name that you made up is going to be pointless. The error message says that you destroyed the dgvProcs object and now you're trying to use it. The line that you commented out in your code snippet would do that if it wasn't commented out before. Me.Controls.Remove(dgvProcs) would detroy the dgvProcs object.

      A guide to posting questions on CodeProject[^]
      Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
           2006, 2007, 2008
      But no longer in 2009...

      H L 2 Replies Last reply
      0
      • D Dave Kreskowiak

        You have a DataGridView on your form that YOU called dgvProcs. So, obviously searching the Internet for a name that you made up is going to be pointless. The error message says that you destroyed the dgvProcs object and now you're trying to use it. The line that you commented out in your code snippet would do that if it wasn't commented out before. Me.Controls.Remove(dgvProcs) would detroy the dgvProcs object.

        A guide to posting questions on CodeProject[^]
        Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
             2006, 2007, 2008
        But no longer in 2009...

        H Offline
        H Offline
        Hypermommy
        wrote on last edited by
        #3

        I'm not so confused that I searched the internet for dgvProcs. I searched the code. Sorry I didn't make that clearer... I guess I just figured it was obvious. And yes, if that line weren't commented out I can see that it would do it. But that line's been commented out the whole time and I'm still getting the error. It's really wierd.

        Denise "Hypermommy" Duggan

        D 1 Reply Last reply
        0
        • D Dave Kreskowiak

          You have a DataGridView on your form that YOU called dgvProcs. So, obviously searching the Internet for a name that you made up is going to be pointless. The error message says that you destroyed the dgvProcs object and now you're trying to use it. The line that you commented out in your code snippet would do that if it wasn't commented out before. Me.Controls.Remove(dgvProcs) would detroy the dgvProcs object.

          A guide to posting questions on CodeProject[^]
          Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
               2006, 2007, 2008
          But no longer in 2009...

          L Offline
          L Offline
          Luc Pattyn
          wrote on last edited by
          #4

          Hi Dave,

          Dave Kreskowiak wrote:

          Me.Controls.Remove(dgvProcs) would detroy the dgvProcs object

          I'm not with you here. Who would be doing the Dispose? Are you saying ControlCollection.Remove(x) actively calls x.Dispose()? (I can't see that in the doc) or x being removed becomes collectible? from the code dgvProcs is a class member, so this reference is still alive. Couldn't the problem be that by setting a new DataSource the Columns[] collection got lost? :confused:

          Luc Pattyn [Forum Guidelines] [My Articles]


          The quality and detail of your question reflects on the effectiveness of the help you are likely to get. Show formatted code inside PRE tags, and give clear symptoms when describing a problem.


          1 Reply Last reply
          0
          • H Hypermommy

            I'm not so confused that I searched the internet for dgvProcs. I searched the code. Sorry I didn't make that clearer... I guess I just figured it was obvious. And yes, if that line weren't commented out I can see that it would do it. But that line's been commented out the whole time and I'm still getting the error. It's really wierd.

            Denise "Hypermommy" Duggan

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

            No, there could be no more references holding on to it. The other thing, that i didn't see earlier, is possibly the columns being wiped out and rebuilt after the data bind. And, of course, the possibility of having to Clean the project, then rebuild.

            A guide to posting questions on CodeProject[^]
            Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
                 2006, 2007, 2008
            But no longer in 2009...

            H 1 Reply Last reply
            0
            • D Dave Kreskowiak

              No, there could be no more references holding on to it. The other thing, that i didn't see earlier, is possibly the columns being wiped out and rebuilt after the data bind. And, of course, the possibility of having to Clean the project, then rebuild.

              A guide to posting questions on CodeProject[^]
              Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
                   2006, 2007, 2008
              But no longer in 2009...

              H Offline
              H Offline
              Hypermommy
              wrote on last edited by
              #6

              Clean the project and rebuild? I'm afraid I don't understand. There's still a lot of tools in Visual Studio that I'm learning... is "clean" one of them? I do appreciate the assistance, believe me! I ended up finding a workaround... I noticed that if I clicked OK on the messagebox that informed me of the error, the system went on ahead and built everything and all looked and acted okay. So what I did was just put a separate catch block in there to catch just the object disposed exception and swallow it up and ignore it. That done, everything appears to work fine. Of course, the "solution" makes me a bit nervous as ignoring exceptions is probably not the safest thing to do..... But maybe it gives a clue to one of you gurus that says what's going on... 'cause this is still too weird to me.

              Denise "Hypermommy" Duggan

              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