Form.Show() Error

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Enij
    New Member
    • Apr 2009
    • 13

    Form.Show() Error

    Hi All,

    If I type this code (VB.net 2003):

    Code:
    Dim myDialog As frmTestDialog
    
    myDialog = New frmTestDialog
    
    myDialog.Show()
    you'd expect some dialog window to appear in a non-modal state. For some reason, this isn't the case with a program I am working on. Most of the dialogs use ShowDialog() to open them, and one uses Show(). The second I try to show another non-modal dialog, the dialog appears in a modal state. Another strange thing is, before I show the dialog, there is code to shift the dialog location to centre it on the main form - this isn't executed either: the dialog appears at 0,0.

    My usual trend is to blame myself for errors (usually the case), then I blame the software; I have checked every single line of code (including the generated code), and it all checks out - the dialog should be non-modal. But ... it's not. I've come across other errors in VB.net 2003; is this another instance?

    I'll try creating a new dialog and displaying this non-modal, and see what happens. If it works, I can just transplant the code ... but ... this shouldn't be happening, just like if I go to a shop, ask for a cola, I expect a cola not a Chinese panda; more annoying, I return the panda, ask for a cola, and they give me the panda back ... do loop until I give up ...

    The system does using threading, but none of that code connects to the display dialog routines - all dialogs are opened with more-or-less the above code (a few have simple validation routines).

    Any help would be appreciated here. I've been coding with VB.net solidly for years, and I've never encountered this before.
  • Enij
    New Member
    • Apr 2009
    • 13

    #2
    Yep, for some reason when I add a new form to the solution, try to show it as non-modal, it appears in a non-modal state...

    Okay, hold the phone ... as part of the validation routine that precedes the dialog.Show(), a ListView control is tested for an item count > 0 -- this listview is part of a threaded routine. The second I comment all the listview code, the dialog shows in a non-modal state (and the dialog is centred on the main form). It's like any connection whatsoever to the listview control is making the dialog become modal (the validation pseudo-code is: check listview for 0 items / if > 0, iterate listview items, creating a comma-delimited string based on listview item text / place the string in the dialog's tag / show dialog non-modal). By adding this string to the dialog tag property, the dialog becomes modal ...

    This happens regardless to the String's scope.

    I can work around this, but I would love to know what is going on here.

    Comment

    • Enij
      New Member
      • Apr 2009
      • 13

      #3
      Wrote quite a few workarounds, even tried a 'cheat' by creating a dialog in thread, and they all failed.

      I'm fairly positive this is a threading issue now. It is strange that my first non-modal dialog works perfectly.

      I have a collection of routines that are run in a separate thread, which access the aforementioned listview control - directly access it, no invoking to the main UI thread, or anything like that (there are some visual glitches that happen when this is done, but by refreshing the control, the glitches vanish). I have a feeling this tardiness of mine is responsible for the error(s).

      I did once invoke to the main UI thread, as there is some old code still commented on the system; not sure why I reverted the code. I'll run through my notes, and retry the invoking technique, see if this cures the problem...

      Comment

      • Enij
        New Member
        • Apr 2009
        • 13

        #4
        Okay ... I'm at a dead-end here.

        Tried using a delegate and invoking to the main UI thread, which failed, as in everything went smoothly, but the dialog is still modal and in the upper-left corner.

        To see if this is a threading issue, I removed all the threading code and called the routine directly. The UI hung as I expected it to, the routine completed, showing results in the listview control, but ... still the dialog opens as modal, and it's in the upper-left corner. So, now I don't think it is a threading issue.

        Before I start this routine, the dialog opens normally. It is after the routine has been called and ends, that is when the dialog goes nuts.

        I've exhausted my VB.net knowledge, and I can't find anything with Google that mentions this type of error. I am loathed to blame VB.net; this is most likely something I've done, but I cannot find what it is.

        Move on a few minutes into new tests ...

        Now this is where things get a little strange. To see if the problem lay with something in the dialog code, I created a new, empty dialog, and hooked it up to display on a button click, commenting the old code out. In my understanding of the universe, when the button is clicked, the new dialog would appear, and for every click, a new dialog. This is what happened.

        Then I ran my listview control routine. The routine completes, and ... this doesn't make any sense. Code that had been commented out is running -- I click the button to load the new, empty dialog, and the old dialog appears (modal, upper-left corner).

        When I worked as a computer engineer, I saw errors (crazy errors) like this when the computer's memory modules were corrupted (one minute a DVD-ROM would read 50 files, then next, it'd read 23 files, etc).

        Anyway, I'm out of ideas. Any help here would be great.

        Comment

        • Plater
          Recognized Expert Expert
          • Apr 2007
          • 7872

          #5
          As for your latest problem:
          If you set breakpoints and run in debug, do your breakpoint circles become empty red circle (instead of filled in ones)?
          It sort of sounds like something is happening at compile time, like maybe something is not being cleaned/built correctly?
          I've had it happen where I didn't pay close enough attention to the build output to see things like "project not selected for build" (vs went crazy and took all of my projects out of the build list) and couldn't figure out why my code wasn't running.

          Comment

          • Enij
            New Member
            • Apr 2009
            • 13

            #6
            Hi Plater,

            Thanks for your quick reply. Things are a tad strange at this end.

            My build list is good -- everything is where it should be. I deleted all the .exes, .pdbs, Release and Debug folders, letting VB recreate them - the error still happens.

            Then, I tried your breakpoints idea, and regardless of what I did or where the breakpoints were set, they were never triggered. Then, I thought maybe another routine had accidentally been told to handle the control's click event (I'm using a label control to act as a button), but the routine handling the click was the only one.

            Then, I commented out the entire click event code, ran the application, and the dialog still appeared in its modal state (X-Files eat your heart out!!) ... there's no code to do anything, yet something happens... Dumbfounded, I placed a button control on the form and rigged it to show the dialog, and it works -- the dialog is being shown as non-modal, doing everything the code tells it to.

            My computer's hard-disk started making some strange, whining noises a few days back (it is 6 years old after all), so I ran the usual checks on all system elements, and they all came back clean. But, just on the off-chance, I put the VB solution on to my new laptop, ran the application, and the same fault happens, letting my old machine and the VB installation off the hook.

            Label controls have a click event, so I'm assuming it's fine to use them as buttons (I use label controls as simple, flat menu icons). Though, saying that, I have bundle of 24x24 labels acting as buttons, and they're all doing their job nicely.

            My breakpoints are displayed as solid red circles.

            I'll try creating another label control, configure it as the other, and transplant the code across, see what happens ...

            EDIT: (after the above test)

            Deleted the old label control, created a new one, and hooked it up to show a dialog in a non-modal state ...

            It works ... it ... WORKS!!!!!! ha hahahahahhahaha aaaa!!!

            ... ahem ...

            Guess the solution was obvious -- if a control stops working correctly, delete it and replace it, before going over-board, tearing your application apart, searching for a problem that isn't there.

            I've been meaning to have a look at the express edition of VB2008, perhaps it's time I did. Does anybody know if VB2008 can be purchased alone, or if it is only available as part of Visual Studio 2008?
            Last edited by Enij; Apr 22 '09, 09:40 PM. Reason: New Information

            Comment

            Working...