VB.NET中ListView控件的操作

         '建立显示控件

Dim LW As New ListView()

 

        '大小及位置

        LW.Bounds = New Rectangle(New Point(6, 40), New Size(522, 227))

        '显示方式

        LW.View = View.Details

        '显示网络线.

        LW.GridLines = True

        '重新排序.

        LW.AllowColumnReorder = True

        '选中整行.

        LW.FullRowSelect = True

        '选择多项.

        LW.MultiSelect = False

        '建立标题.

        LW.Columns.Add("姓名", 80, HorizontalAlignment.Left)

        LW.Columns.Add("编号", 150, HorizontalAlignment.Left)

        LW.Columns.Add("身份证号", 150, HorizontalAlignment.Left)

        '设立列表高度.

        '建立一个图像.

        Dim IL As New ImageList

        '设置图像大小.

        IL.ImageSize = New Size(1, 20)

        LW.SmallImageList = IL

        '将控件添加显示.

    Me.GroupBox1.Controls.Add(LW)

 

 

 

#Region "  查询操作"

    Private Sub TextBox1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox1.TextChanged

        Try

            If Me.TextBox1.Text.Length > 0 Then

                Dim T As String = "Select Top 100 姓名,编号,身份证号 From DaLiYongUsers Where " & _

                "编号 Like '%{0}%' Or 姓名 Like '%{1}%' Or 拼音缩写 Like '%{2}%' Or 电话 Like '%{3}%' Or 手机 Like '%{4}%' Or 身份证号 Like '%{5}%' Or 单位 Like '%{6}%' Or 备注 Like '%{7}%'"

                T = String.Format(T, Me.TextBox1.Text, Me.TextBox1.Text, Me.TextBox1.Text, Me.TextBox1.Text, Me.TextBox1.Text, Me.TextBox1.Text, Me.TextBox1.Text, Me.TextBox1.Text)

                Dim DT As DataTable = DB.RunSelectTable(T)

                If DT.Rows.Count > 0 Then

                    LW.Items.Clear()

                    Dim LWI As ListViewItem

                    Dim B As Boolean = False

                    For Each R As DataRow In DT.Rows

                        LWI = New ListViewItem(R.Item("姓名").ToString)

                        LWI.SubItems.Add(R.Item("编号").ToString)

                        LWI.SubItems.Add(R.Item("身份证号").ToString)

                        '隔行颜色.

                        If B Then

                            LWI.BackColor = Color.LavenderBlush

                        End If

                        B = Not B

                        '添加到列表.

                        LW.Items.Add(LWI)

                    Next

                    LW.Visible = True

                Else

                    LW.Visible = False

                End If

            Else

                LW.Visible = False

            End If

        Catch ex As Exception

 

        End Try

    End Sub

#End Region

你可能感兴趣的:(VB.NET中ListView控件的操作)