简体   繁体   English

在vb.net中检查一个文本框中所有删除行中的数字

[英]check numbers in one textbox delete line in all in vb.net

i have 6 textboxs in total box4 has a range of numbers 1.76, 5.6 2.89 etc. i want to check if the number is over 2 and if so delete and then delete that line in the 5 other text boxes, i know its a mess i changed my code it will work from some figures but not others 我在box4中总共有6个文本框,其数字范围为1.76、5.6 2.89等。我想检查数字是否超过2,如果是,请删除,然后再在其他5个文本框中删除该行,我知道那是一团糟更改了我的代码,它仅适用于某些数据,而不适用于其他

      Dim list1 As List(Of String) = TextBox1.Lines.ToList
    Dim list2 As List(Of String) = TextBox2.Lines.ToList
    Dim list3 As List(Of String) = TextBox3.Lines.ToList
    Dim list4 As List(Of String) = TextBox4.Lines.ToList
    Dim list5 As List(Of String) = TextBox5.Lines.ToList
    Dim list6 As List(Of String) = TextBox6.Lines.ToList
    Dim t As Int32
    Dim lin As String

    t = 1
    lin = TextBox4.Lines(t).ToString()

    Do Until t = TextBox4.Lines.Count

        If lin > 2 Then


            list1.RemoveAt(t)
            TextBox1.Lines = list1.ToArray
            list2.RemoveAt(t)
            TextBox2.Lines = list2.ToArray
            list3.RemoveAt(t)
            TextBox3.Lines = list3.ToArray
            list5.RemoveAt(t)
            TextBox5.Lines = list5.ToArray
            list6.RemoveAt(t)
            TextBox6.Lines = list6.ToArray
            list4.RemoveAt(t)
            TextBox4.Lines = list4.ToArray

            t += 1

        End If

    Loop

It's not clear what your example code is going to do. 目前尚不清楚您的示例代码将要做什么。

What you can do is trap the 'validating' event of the textbox and then update the other textboxes in the code you run when this event is fired. 您可以做的是捕获文本框的“ validating”事件,然后在触发该事件时在您运行的代码中更新其他文本框。

The 'validating' event is documented here . 此处记录 “验证”事件。 It is a generic event that applies to many WinForms controls including textboxes. 这是一个通用事件,适用于许多WinForms控件,包括文本框。

Edit: 编辑:

Here's a code sample for the code for Form1 if there are 4 textboxes and nothing else on a basic form: 如果有4个文本框,而基本表单上没有其他内容,这是Form1的代码的代码示例:

Public Class Form1
    Private Sub TextBox1_Validating(sender As Object, e As CancelEventArgs) Handles TextBox1.Validating
        Dim Input As String

        ' get input
        Input = Me.TextBox1.Text

        ' assume input is space delimited
        For Each Item As String In Input.Split(" ").ToList
            If IsNumeric(Item) Then
                If Convert.ToDouble(Item) > 2 Then
                    Me.TextBox2.Text = Me.TextBox2.Text.Replace(Item, String.Empty)
                    Me.TextBox3.Text = Me.TextBox3.Text.Replace(Item, String.Empty)
                    Me.TextBox4.Text = Me.TextBox4.Text.Replace(Item, String.Empty)
                End If
            End If
        Next

    End Sub
End Class

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

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