VB.NET toolbar in mdi parent window
-
Hello! I'm creating a simple VB.NET data application. I have a MDIparent form which will open up my child forms. I have no problem opening up my child forms with a menu bar. Although for looks, I have added a toolbar to the MDI parent window, so a user can select the form of choice by cliking on a picture (like a pushbutton). I have a toolbar set with 4 icons, for my 4 different forms. I have an imagelist made to complement the buttons so they look nice and pretty. Now for the problem...When I add code for the toolbar to signify which button is pressed (I wrote case statements), I can only open up one form. If I open up another form after closing the first one, or try to open up 2 forms at one time, I get the following error when in Debug mode: "An unhandled exception of type 'System.Data.NoNullAllowedException' occurred in system.windows.forms.dll Additional information: Column 'ID_uniqe' does not allow nulls." The debug will highlight in Green my show() statement of the form I try to open. Here is my code for signigiy which button is pressed on the toolbar: Private Sub ToolBar1_ButtonClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.ToolBarButtonClickEventArgs) Handles ToolBar1.ButtonClick Dim m As New DataForm_Main Dim p As New DataForm_PrHist Select Case ToolBar1.Buttons.IndexOf(e.Button) Case Is = 0 m.MdiParent = Me m.Show() Case Is = 1 p.MdiParent = Me p.Show() End Select End Sub AS A NOTE: This coding works fine if I decide to not have child windows. If I completely remove the "m.MdiParent = Me" statements, then the forms open up nicely with no errors - Errors seem to only produce when I have them set for MDI's. Should I even be using case statement? How can I show the forms in MDI child windows within my parent form?
-
Hello! I'm creating a simple VB.NET data application. I have a MDIparent form which will open up my child forms. I have no problem opening up my child forms with a menu bar. Although for looks, I have added a toolbar to the MDI parent window, so a user can select the form of choice by cliking on a picture (like a pushbutton). I have a toolbar set with 4 icons, for my 4 different forms. I have an imagelist made to complement the buttons so they look nice and pretty. Now for the problem...When I add code for the toolbar to signify which button is pressed (I wrote case statements), I can only open up one form. If I open up another form after closing the first one, or try to open up 2 forms at one time, I get the following error when in Debug mode: "An unhandled exception of type 'System.Data.NoNullAllowedException' occurred in system.windows.forms.dll Additional information: Column 'ID_uniqe' does not allow nulls." The debug will highlight in Green my show() statement of the form I try to open. Here is my code for signigiy which button is pressed on the toolbar: Private Sub ToolBar1_ButtonClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.ToolBarButtonClickEventArgs) Handles ToolBar1.ButtonClick Dim m As New DataForm_Main Dim p As New DataForm_PrHist Select Case ToolBar1.Buttons.IndexOf(e.Button) Case Is = 0 m.MdiParent = Me m.Show() Case Is = 1 p.MdiParent = Me p.Show() End Select End Sub AS A NOTE: This coding works fine if I decide to not have child windows. If I completely remove the "m.MdiParent = Me" statements, then the forms open up nicely with no errors - Errors seem to only produce when I have them set for MDI's. Should I even be using case statement? How can I show the forms in MDI child windows within my parent form?
First, you might want to move the Dim statements into the Case Is blocks. Its a better idea to allocate the new forms as you need them, not before you determine that. This will save the garbage collector some time because it doesn't have to destroy objects that were never used. Second, the problem doesn't appear to be in your code snippet. I can use the exact same code and create new forms all day. Judging by the error message, the problem appears to be in the child form itself, not with the parent. You might be doing something that is not allowed in a child form, although I can't fathom what that might be. Its also possible you might have a data binding problem where pages/records/fields are getting locked and a bind is failing on the second form. You'll have to trace into the creation of the child form to find out whats going on. Set a breakpoint on the Show statement and run your app. When you click on the button to create the new child, the debugger will stop on the Show statement. Hit F11 to step into the child form to see what's going on. RageInTheMachine9532