Hy It's a long time ago i asked something here.
But now i am asking again something

First i give my code

    Dim conc As New SqlConnection("Data Source=(LocalDB)\MSSQLLocalDB;AttachDbFilename=|DataDirectory|\BurgerlijkeStand.mdf;Integrated Security=True;Connect Timeout=30")
                conc.Open()
                Dim cmdc As New SqlCommand("Select COUNT (*) FROM dbo.[Landen] ", conc)
                Dim i As Integer = cmdc.ExecuteScalar()
                cmdc = Nothing
                conc.Close()

                If i > 0 Then
                    Dim myConn As New SqlConnection("Data Source=(LocalDB)\MSSQLLocalDB;AttachDbFilename=|DataDirectory|\BurgerlijkeStand.mdf;Integrated Security=True;Connect Timeout=30")
                    Dim cmd As New SqlCommand
                    Dim dr As SqlDataReader
                    cmd.Connection = myConn
                    myConn.Open()
                    cmd.CommandText = "Select * FROM dbo.[Landen] where Landen = '" & TextBox4.Text & "'"
                    dr = cmd.ExecuteReader
                    While (dr.Read)
                        Dim subitem As ToolStripMenuItem = Form1.DoopgegevensToolStripMenuItem1 ' 1st level
                        Dim subitem1 As ToolStripMenuItem = New ToolStripMenuItem ' 2nd level
                        Dim subitem2 As ToolStripMenuItem = New ToolStripMenuItem ' 3rd level
                        Dim subitem3 As ToolStripMenuItem = New ToolStripMenuItem ' 3rd level
                        Dim col2 As String = (dr("Landen"))
                        If col2 = "Duitsland" Then

                            subitem.DropDownItems.Add(subitem1)
                            subitem1.Text = col2

                            subitem1.DropDownItems.Add(subitem2)
                            subitem2.Text = "Alle dopen " + col2
                            subitem1.DropDownItems.Add(subitem3)
                            subitem3.Text = "Deelstaat " + col2
                            subitem3.ToolTipText = "Alla dopen van deelstaat " + col2
                        End If    

                        If col2 = "Luxemburg" Then    
                            subitem.DropDownItems.Add(subitem1)
                            subitem1.Text = col2

                            subitem1.DropDownItems.Add(subitem2)
                            subitem2.Text = "Alle dopen " + col2
                            subitem1.DropDownItems.Add(subitem3)
                            subitem3.Text = "District " + col2
                            subitem3.ToolTipText = "Alle dopen van District " + col2
                        End If

                        If col2 <> "Luxemburg" And col2 <> "Duitsland" Then    
                            subitem.DropDownItems.Add(subitem1)
                            subitem1.Text = col2

                            subitem1.DropDownItems.Add(subitem2)
                            subitem2.Text = "Alle dopen " + col2
                            subitem1.DropDownItems.Add(subitem3)
                            subitem3.Text = "Provincie " + col2
                            subitem3.ToolTipText = "Alle dopen van District " + col2
                        End If    
                    End While
                    myConn.Close()
                End If

This is all created in form 2

But how can i make the folowing clickable in form 1

  subitem1.DropDownItems.Add(subitem2)
                                subitem2.Text = "Alle dopen " + col2
                                subitem1.DropDownItems.Add(subitem3)
                                subitem3.Text = "Provincie " + col2
                                subitem3.ToolTipText = "Alle dopen van District " + col2

Thanks in advice John

You must have to add eventhandler to do any job by a dynamic control.

subitem1.DropDownItems.Add(subitem2)
subitem2.Text = "Alle dopen " + col2
AddHandler subitem2.Click, AddressOf Me.Click2

Here Click2 is a userdefined sub procedure, which can perfom on click event of subitem2 submenu.

Yes you are right I didn't thought about that, Thanks for the reply

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.