Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 306
  • Last Modified:

bind list to textbox vb.net

Hi,

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
            Me.Controls.Add(labelMap)
            AddHandler labelMap.TextChanged, AddressOf ChangeHeight
            AddHandler labelMap.MouseMove, AddressOf MoveLabel
            .Focus()
            .Text = text
        End With
    End Sub

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

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

    Private Sub PasteLabel()
        CreateLabel(copyText)
    End Sub

    Private Sub AddChild(ByVal sender As Object)
        CreateLabel()
        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
                TextBox.Dispose()
            End If
        Next
    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
        CreateLabel()
    End Sub

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

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

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

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

    Private Sub MenuClearMap_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MenuClearMap.Click
        ClearMap()
    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


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


Thanks in advance
Peter
0
Mutsop
Asked:
Mutsop
  • 2
1 Solution
 
rspahitzCommented:
Why not just use a combobox, since by design it is a text box with a list box built in?
0
 
rspahitzCommented:
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.
0

Featured Post

 [eBook] Windows Nano Server

Download this FREE eBook and learn all you need to get started with Windows Nano Server, including deployment options, remote management
and troubleshooting tips and tricks

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now