bind list to textbox

Posted on 2011-10-18
Last Modified: 2012-05-12

I'm creating a mindmapper application (as a test) and have a difficulty to manage created mindlabels and their childlabels.

So I thought of binding a list(Of textbox) to a textbox. But how can this be done?
Or do you have another idea? :)

Here is the code I have so far for the application:
Public Class Main

#Region "Methods"
    Private WithEvents labelMap As TextBox
    Private copyText As String
    Private menuPosition As Point

    Private Sub CreateLabel(Optional ByVal text As String = "")
        labelMap = New TextBox
        With labelMap
            .Location = New Point(menuPosition.X, menuPosition.Y)
            .Multiline = True
            .AutoSize = True
            .ContextMenuStrip = MenuLabel
            AddHandler labelMap.TextChanged, AddressOf ChangeHeight
            AddHandler labelMap.MouseMove, AddressOf MoveLabel
            .Text = text
        End With
    End Sub

    Private Sub DeleteLabel(ByVal sender As Object)
        labelMap = GetMenuControl(sender)
    End Sub

    Private Sub CopyLabel(ByVal sender As Object)
        labelMap = GetMenuControl(sender)
        copyText = labelMap.Text
        MenuPasteLabel.Enabled = True
    End Sub

    Private Sub PasteLabel()
    End Sub

    Private Sub AddChild(ByVal sender As Object)
        Dim startLocation As New Point(GetMenuControl(sender).Location)
        Dim endLocation As New Point(labelMap.Location)

        ControlPaint.DrawReversibleLine(startLocation, endLocation, Color.Blue)
    End Sub

    Private Sub ClearMap()
        For Each TextBox As Control In Me.Controls
            If TypeOf TextBox Is TextBox Then
            End If
    End Sub

    Private Sub ChangeHeight(ByVal sender As System.Object, ByVal e As System.EventArgs)
        'nog aan te passen
        labelMap.Height = labelMap.Lines.Count * 20
    End Sub

    Private Sub MoveLabel(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs)
        menuPosition = New Point(Me.PointToClient(MousePosition))
        If e.Button = MouseButtons.Left Then
            labelMap.Location = New Point(menuPosition)
        End If
    End Sub

    Private Function GetMenuControl(ByVal sender As Object) As Control
        Dim Menu As ToolStripMenuItem = CType(sender, ToolStripMenuItem)
        Dim MenuControl As ContextMenuStrip = CType(Menu.Owner, ContextMenuStrip)

        Return MenuControl.SourceControl
    End Function
#End Region

#Region "Event Handlers"
    Private Sub MenuNewLabel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MenuNewLabel.Click
    End Sub

    Private Sub MenuDeleteLabel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MenuDeleteLabel.Click
    End Sub

    Private Sub MenuCopyLabel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MenuCopyLabel.Click
    End Sub

    Private Sub MenuPasteLabel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MenuPasteLabel.Click
    End Sub

    Private Sub MenuAddChild_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MenuAddChild.Click
    End Sub

    Private Sub MenuClearMap_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MenuClearMap.Click
    End Sub

    Private Sub Main_MouseUp(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Me.MouseUp
        If e.Button = MouseButtons.Right Then
            menuPosition = New Point(Me.PointToClient(MousePosition))
        End If
    End Sub
#End Region
End Class

Open in new window

2 ContextMenuStrips
-1: FormLabel: "New Label", "Clear Map"
-2: MenuLabel: "Add Child", "Copy", "Delete"

Thanks in advance
Question by:Mutsop
    LVL 22

    Expert Comment

    Why not just use a combobox, since by design it is a text box with a list box built in?
    LVL 22

    Accepted Solution

    The next step would be to use the Items collection to add items to the lists.
    You can also define the settings so that your entries are limited to the list or available from the list or manual entries not in the list.

    Featured Post

    How your wiki can always stay up-to-date

    Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
    - Increase transparency
    - Onboard new hires faster
    - Access from mobile/offline

    Join & Write a Comment

    It’s quite interesting for me as I worked with Excel using for some time. Here are some topics which I know want to share with others whom this might help. First of all if you are working with Excel then you need to Download the Following …
    A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
    This video discusses moving either the default database or any database to a new volume.
    This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor ( If you're looking for how to monitor bandwidth using netflow or packet s…

    745 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    14 Experts available now in Live!

    Get 1:1 Help Now