2015-09-02 80 views
0

我有一個組合框和文本框。在文本框中的特定文本或單詞之後添加文本vb.net

組合框將有供用戶選擇的選項。

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 

回答

0

這裏的更新之一,有很好的一個!

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 Sub 
+0

嘿克里斯,多數民衆贊成在非常有趣的...但我需要在「故障排除步驟:」後的任何想法如何做到這一點? – Kenster

+0

對不起,我錯過了一些解釋,我想第二個按鈕「跟進:」與第二個組合框/按鈕2。 – Kenster

相關問題