查找任何控件并将值放入文本框行

时间:2019-04-02 17:14:30

标签: vb.net

使用此代码,信息将在几个文本框中发送。我只想在名称为Textbox3.Lines(i)的文本框行中发送,所以我尝试了此代码。

For i As Integer = 1 To 100
    Dim firstBoxList = TxtIntDraws.Lines(i).Split(",").ToArray
    Dim secondBoxList = TxtIntDraws.Lines(i + 1).Split(",").ToList()
    Dim intersectionList = firstBoxList.Intersect(secondBoxList)
    Dim Line = TxtIntDraws.Lines(i)
    For Each str As String In intersectionList
        Dim sb As New StringBuilder()
        'inside the loop
        sb.AppendLine(str & ",")
        'and after the loop
        'This will prevent the textbox from having to repaint on every iteration
        TextBox3.Text = sb.ToString
    Next
Next

此代码不起作用,因为它仅显示一个值,而不是全部,实际上会重置并显示找到的最后一个值。

1 个答案:

答案 0 :(得分:0)

我认为您不需要在每次迭代时都将其添加到TextBox中。只需将所有字符串存储为迭代到100,然后在最后更新TextBox。

Dim intersectionList As New List(Of String)()
For i As Integer = 1 To 100
    Dim firstBoxList = TxtIntDraws.Lines(i).Split(",")
    Dim secondBoxList = TxtIntDraws.Lines(i + 1).Split(",")
    intersectionList.Add(String.Join(", ", firstBoxList.Intersect(secondBoxList)))
Next
TextBox3.Text = String.Join(Environment.NewLine, intersectionList)