Quantcast
Channel: VBForums - Visual Basic .NET
Viewing all articles
Browse latest Browse all 27389

[RESOLVED] Changing Runtime Generated Checkbox Names in Runtime Generated Groupbox

$
0
0
Hey Everybody,

I am having an issue changing runtime generated checkbox names in runtime generated groupboxes. I am using multiple groupboxes, and then taking all of the rows in a database and creating checkboxes for them. The checkbox names are as follows ""chkClass" & intGroupBoxNumber & intCurrentRow". Upon deletion of a groupbox, I renumber all of the current group boxes, and would like the checkbox names to change as well to the new groupbox number, if this makes any sense. My code is as follows:

Code:

strControlName = "grpGroup" & strIBResult
            Try
                intGroupBoxOldYLocation = Me.Controls(strControlName).Location
                Me.Controls(strControlName).Dispose()
                MessageBox.Show("Deleted: " & strControlName)
                intRenameGroup = strIBResult + 1

                Try
                    strControlName = "grpGroup" & intRenameGroup
                    strControlNewName = "grpGroup" & intRenameGroup - 1
                    Me.Controls(strControlName).Location = intGroupBoxOldYLocation
                    Me.Controls(strControlName).Text = "Group " & intRenameGroup - 1
                    Me.Controls(strControlName).Name = strControlNewName
                    MessageBox.Show("Changed: " & strControlName & " to: " & strControlNewName)
                   
                    Do While intCurrentClassRow < intTotalClassRows
                        strCheckBoxOldName = "chkClass" & intRenameGroup & intCurrentClassRow
                        strCheckBoxNewName = "chkClass" & intRenameGroup - 1 & intCurrentClassRow
                        MessageBox.Show("Renaming: " & strCheckBoxOldName & " to: " & strCheckBoxNewName)
                        Me.Controls(strCheckBoxOldName).Name = strCheckBoxNewName
                        intCurrentClassRow += 1
                        MessageBox.Show("Renamed: " & strCheckBoxOldName & " to: " & strCheckBoxNewName)
                    Loop

                    intCurrentClassRow = 0
                    intRenameGroup += 1
                    intGroupBoxNewYIncrement = intGroupBoxOldYLocation.Y + Me.Controls(strControlNewName).Height + 50

                    Do
                        strControlName = "grpGroup" & intRenameGroup
                        strControlNewName = "grpGroup" & intRenameGroup - 1
                        Me.Controls(strControlName).Location = New Point(intCurrentXPosition, intGroupBoxNewYIncrement)
                        Me.Controls(strControlName).Text = "Group " & intRenameGroup - 1
                        Me.Controls(strControlName).Name = strControlNewName

                        Do While intCurrentClassRow < intTotalClassRows
                            strCheckBoxOldName = "chkClass" & intRenameGroup & intCurrentClassRow
                            strCheckBoxNewName = "chkClass" & intRenameGroup - 1 & intCurrentClassRow
                            Me.Controls(strCheckBoxOldName).Name = strCheckBoxNewName
                            intCurrentClassRow += 1
                            MessageBox.Show("Renamed: " & strCheckBoxOldName & " to: " & strCheckBoxNewName)
                        Loop

                        intCurrentClassRow = 0
                        intRenameGroup += 1
                        intGroupBoxNewYIncrement = intGroupBoxNewYIncrement + Me.Controls(strControlNewName).Height + 50
                    Loop

                Catch ex As Exception
                    MessageBox.Show("Control: " & strControlName & " does not exist")
                    MessageBox.Show(ErrorToString)
                End Try

            Catch ex As Exception
                'MessageBox.Show("Control: " & strControlName & " never existed")
                MessageBox.Show("Please enter a valid group number to delete.", "Invalid Entry")
                Exit Sub
            End Try

I am pretty sure my trouble now exists at the Me.Controls(strCheckBoxOldName).Name = strCheckBoxNewName.

The error is as follows: "Object reference not set to an instance of an object"

Is there a different method to reference that runtime generated groupbox?


Thanks. Sorry if this is confusing!

Viewing all articles
Browse latest Browse all 27389

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>