我有一个组合框和一个文本框。
该组合框将有选项供用户选择。
在textbox的属性中设置了Textbox1:- Troubleshooting Steps:。
如果用户从组合框列表中选择:Rebooted PC,然后按下一个按钮,它将在Troubleshooting Steps:之后添加文本。
示例:Troubleshooting Steps: Rebooted PC
我想要做的是一个接一个地添加多个选择。
示例:
Troubleshooting Steps: Rebooted PC- Problem returned after reboot- Replaced part我做了一些谷歌搜索,找到了这段代码,我修改了它的一部分。
但我的问题是,它会将最后选择的文本添加到Troubleshooting Steps:,将第一个选择的文本推送到末尾。
发生了什么?示例:
Troubleshooting Steps: (3rd)Replaced part- (2nd)Problem returned after reboot- (1st)Rebooted PC代码:
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim text As String = TextBox1.Text
Dim index As Integer = text.IndexOf("Troubleshooting Steps:")
Dim countChars As Integer
countChars = "Troubleshooting Steps:".Length
If index >= 0 Then
text = text.Insert(index + countChars, ComboBox1.Text)
TextBox1.Text = text
End If
End Sub发布于 2015-09-02 20:18:43
这是最新的版本,祝你有一个好的版本!
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'you can set the TextBox text either here or in the properties panel
TextBox1.Text = "Troubleshooting Steps: "
TextBox2.Text = "Follow up: "
End Sub
Private Sub Button1_Click(ByVal sender As Object, ByVal e As EventArgs) Handles Button1.Click
If ComboBox1.SelectedIndex < 0 Then
'MsgBox("Your message if nothing is selected in ComboBox1 when the button is pressed")
Else
TextBox1.Text = TextBox1.Text & " - " & ComboBox1.SelectedItem.ToString
End If
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
If ComboBox2.SelectedIndex < 0 Then
'MsgBox("Your message if nothing is selected in ComboBox2 when the button is pressed")
Else
TextBox2.Text = TextBox1.Text & " - " & ComboBox2.SelectedItem.ToString
End If
End Subhttps://stackoverflow.com/questions/32350928
复制相似问题