简体   繁体   English

vb.net在运行时追加组合框文本?

[英]vb.net append combobox text at runtime?

Hi I have a combobox with a list of presets populating it. 嗨,我有一个组合框,里面有一组预设列表。 What I would like is that if a preset is changed (tweeked) that the selected item in the combobox appends the existing text... 我想要的是,如果更改了预设(tweeked),则组合框中的所选项目将追加现有文本...

as example if the combobox item is original (from form load event) displayed as cube... and I edit the preset that the text in the combobox now displays Cube...(edited)... what i dont want though is a new item added called Cube...(edited) I just want to append the existing item named Cube... to Cube edited... 例如,如果组合框项目是原始的(来自表单加载事件)显示为多维数据集...,并且我编辑了预设,即组合框中的文本现在显示了多维数据集...(已编辑)...我不想要的是添加了名为Cube ...的新项目(已编辑)我只想将名为Cube ...的现有项目附加到已编辑的Cube ...

is this possible? 这可能吗?

Ok, I made this in c# and used the translator to convert it into Visual Basic. 好的,我在c#中进行了此操作,并使用翻译器将其转换为Visual Basic。
It should do the trick from what i can understand from your question. 我应该从您的问题中了解到这一点。

Public Class Form1

Dim OLDDATA As String

Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
    Dim myItems = New List(Of String)
    myItems.Add("Hello")
    myItems.Add("World")
    myItems.Add("Cube")

    For Each item As String In myItems
        ComboBox1.Items.Add(item)
    Next

End Sub

Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
    Try
        ComboBox1.Items.Remove(OLDDATA)
        ComboBox1.Items.Add(ComboBox1.Text)
        ComboBox1.Update()
    Catch ex As Exception
        MessageBox.Show(ex.Message)
    End Try
End Sub

Private Sub ComboBox1_Click(sender As Object, e As EventArgs) Handles ComboBox1.Click
    OLDDATA = ComboBox1.Text
End Sub
End Class

If you have any trouble with it, let me know and I will do my best to reply to you quickly. 如果您有任何问题,请告诉我们,我们将尽力尽快答复您。
Happy Coding! 编码愉快!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM