1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52
| Public Class Form1
Private flagmark As Integer
Private flagfound As Boolean = False
Private Sub Form1_Load(sender As Object, e As System.EventArgs) Handles Me.Load
ListView1.Items.Add("A56601CB30510000")
ListView1.Items.Add("A56602CB30510000")
ListView1.Items.Add("A56603CB30510000")
ListView1.Items.Add("A56604CB30510000")
ListView1.Items.Add("BF2EA6A46A160000")
ListView1.Items.Add("A78D4166193C0000")
ListView1.Items.Add("59504DAA96298000")
ListView1.Items.Add("D424EC43B9C93000")
End Sub
Private Sub TextBox1_TextChanged(sender As Object, e As System.EventArgs) Handles TextBox1.TextChanged
TextBox1.Text = TextBox1.Text.Replace(" ", "")
Dim count As Integer = 0
Dim mark As Integer
Dim str As String
For index As Integer = ListView1.Items.Count - 1 To 0 Step -1
If TextBox1.Text = "" Then
ListView1.Items(index).ForeColor = Color.Black
Else
If Microsoft.VisualBasic.Left(ListView1.Items(index).SubItems(0).Text, TextBox1.Text.Length) = TextBox1.Text Then
ListView1.Items(index).ForeColor = Color.Red
mark = index
count += 1
Else
ListView1.Items(index).ForeColor = Color.Transparent
End If
End If
Next
If count = 1 Then
If Not flagfound Then
flagmark = mark
End If
flagfound = True
str = ListView1.Items(mark).Text
ListView1.Items.RemoveAt(mark)
ListView1.Items.Insert(0, str)
ListView1.Items(0).ForeColor = Color.Red
End If
If DirectCast(sender, TextBox).Text = String.Empty AndAlso flagfound Then
str = ListView1.Items(0).Text
ListView1.Items(0).Text = ListView1.Items(1).Text
ListView1.Items.Insert(flagmark, str)
flagfound = False
End If
End Sub
End Class |
Partager