VB.net Form not displaying controls

rommelit
rommelit used Ask the Experts™
on
I have created a windows form based on a C# coded app.  I am translating to VB.  The appl will consist of a few different forms but in translation I am having a problem with the controls appearing on the form.  Right now I have a main form with a button that will show the ManagePermissions form.  

I have attached the code for the ManagePermissions form.  When I click the "Show Permissions" button on the main form my form comes up blank.  

Thanks in advance ManagePermissions.txt
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®

Author

Commented:
Any thoughts out there? I know it's the holidays but perhaps someone could pop a suggestion up.

Author

Commented:
I have played with this a bit and I think it's an issue with the InitializeComponent sub.  Everything I read points to the fact that the VB designer should be automating the InitializeComponent sub.  Perhaps I translated something wrong when I converted C# to VB?
What version of Visual Studio are you using? VS 2005, 2008, 2010? I'm trying to replicate this, but it's hard without the resources file (.resx).
Fundamentals of JavaScript

Learn the fundamentals of the popular programming language JavaScript so that you can explore the realm of web development.

Author

Commented:
Elrond - VS2008.  You can download from here.  You will need to create the DB and change connection strings with the text file inside the project folder.  Apptly named "Copy of ControlSecurity.sql"
I'm also using VS 2008. Once I found all the occurrences of the SQL connection string and redirected them to my server, everything ran correctly. I can see the ManagePermissions form with its controls on it, though I'm not seeing anything in the Role Name or Current Status blocks, and the RolesBindingNavigator is inactive because it shows no records. However, you didn't give me any records for the SQL database; I have the structure only.

Be that as it may, I'm seeing the controls on the ManagePermissions form, while you're not. It certainly is problematic to mess with the InitializeComponents sub, and such changes are prone to be overwritten. But what you have seems to work properly. When I first got your text file, I wondered if the problem was that your InitializeComponents was in the .vb file, rather than the .designer.vb file, but that's not an issue in the full solution you sent.

Author

Commented:
So the form loads with all controls and reads the DB correctly?  I am getting an error when clicking Button1 "Column 'ControlID' does not belong to table controlsToRoles."
I didn't get that error when the database was empty. Once I entered some data I got the same error, but that makes sense, because the column name in controlsToRoles is FKControlID. However, that's actually a misleading error message; the datatable that's being loaded is actually Roles. Your queryString definition is at issue; first you define it, then you're overwriting it in the "If ByControlRB.Checked" decision tree. I think you probably want the ORDER BY appended to the first string; I'm not sure what the Else is supposed to result in. So it should probably be something like:

If ByControlRB.Checked Then
            queryString &= "ORDER BY ControlID"

Note the & just before the =, which means add the new text to the end of the existing text.

Your use of "&" between two literal text strings doesn't make any sense; is something else supposed to go in the middle? In your original queryString definition, it would make no difference if it were all one long string, with the ampersands (and related opening and closing quotes) removed. What is your intention here?

Author

Commented:
I removed the literal text strings as I was playing with the code.  The correct code should have been similar to the order by ControlID but instead of ControlID I would sort by RoleName.

Here is the end game.  I want to perfect this test application and integrate it into a larger program. (This is actually a test app hence the sloppy code).  I have been trying to develop a security interface that allows Admins to enable and disable features based on the role then assign users to that role.  (I am not tying the app to a domain hence why I am not using iPricipal.)

Does this make sense?
OK, so the idea is that a particular control (textbox, checkbox, etc.) is usable by certain people and not others, based on the role they are assigned to. That seems like a reasonable idea. Your application would then read the database when a user logs in, and enable/disable/hide controls based on what is in the database.

If you change the IF statement as I showed in my prior post, and turn on the ByControlRB radiobutton, ManagePermissions loads properly. The current code doesn't seem to be enough to add new records. But we're a long way from a form coming up blank.

Author

Commented:
No.  I have other code I am working on for the events you speak of.

Before I close; can you advise as to why the PermissionTree doesnt populate properly?
What do you mean by not populating properly? Once I fixed queryString, I'm getting entries in PermissionTree for each row in ControlsToRoles.

Author

Commented:
I get the role 'Limited" but it only lists 'enabled'  where it should list the role and control description.  An example would be:
Button1: visible and enabled

It's part of this code:
PermissionTree.BeginUpdate()
        PermissionTree.Nodes.Clear()
        Dim parentNode As TreeNode = Nothing
        Dim subNode As TreeNode = Nothing

        Dim currentName As String = String.Empty
        For Each row As DataRow In dt.Rows
            Dim subNodeText As String = If(ByControlRB.Checked, row("RoleName").ToString(), row("ControlID").ToString())
            subNodeText = ":"
            subNodeText = If(Convert.ToInt32(row("Invisible")) = 0, " visible ", " not visible ")
            subNodeText = " and "
            subNodeText = If(Convert.ToInt32(row("Disabled")) = 0, " enabled ", " disabled ")

            subNode = New TreeNode(subNodeText)
            Dim dataName As String = If(ByControlRB.Checked, row("ControlID").ToString(), row("RoleName").ToString())
            If currentName <> dataName Then
                parentNode = New TreeNode(dataName)
                currentName = dataName
                PermissionTree.Nodes.Add(parentNode)
            End If

            If parentNode IsNot Nothing Then
                parentNode.Nodes.Add(subNode)
            End If
        Next
        PermissionTree.EndUpdate()
You've got the same problem of overwriting rather than appending text; change all the "subNodeText =" to "subNodeText &=" and I think you'll like the results much more.

Author

Commented:
Probably the most help I have ever received from an Expert!  Thanks for paying it forward to a novice just trying to learn.
Glad to help. I've been in your shoes...

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial