注册 登录
编程论坛 VB.NET论坛

如何让ListView与TextBox1同步。

h42537024 发布于 2008-08-17 15:21, 1040 次点击
请教各位高手。我刚学VB。遇到了难题了。
下面的代码如何让ListView与TextBox1同步。
Imports System.Data
'System.Data.SqlClient名字空间是SQL Server的.NET Framework数据提供程序
Imports System.Data.SqlClient
Public Class name
    Private Sub name_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Me.ListView1.Items.Clear()
        Dim sqlstr As String
        Dim count As Integer
        Dim i As Integer
        Dim Dataset As New DataSet()
        Try
            Dataset.Clear()
            sqlstr = "SELECT * FROM admin"
            Dataset = GetDataFromDB(sqlstr)
            count = Dataset.Tables(0).Rows.Count
            Dim lvItem As New ListViewItem()
            For i = 0 To count - 1
                lvItem.Text = Dataset.Tables(0).Rows(i)("id")
                lvItem.SubItems.Add(Dataset.Tables(0).Rows(i)("用户名"))
                lvItem.SubItems.Add(Dataset.Tables(0).Rows(i)("密码"))
                ListView1.Items.Add(lvItem)
                lvItem = New ListViewItem()

            Next

        Catch
        End Try

        c_id = "这里该如何写才能获取与上面ListView选定项的值?"
        sqlstr = "select * from admin where ID='" & c_id & "'"
        Dataset = GetDataFromDB(sqlstr)

        Me.TextBox1.Text = Trim(Dataset.Tables(0).Rows(0)("用户名"))
 End Sub
End Class
0 回复
1