p2p.wrox.com Forums

p2p.wrox.com Forums (http://p2p.wrox.com/)
-   VB.NET 2002/2003 Basics (http://p2p.wrox.com/vb-net-2002-2003-basics-76/)
-   -   list view to text boxes!! (http://p2p.wrox.com/vb-net-2002-2003-basics/86076-list-view-text-boxes.html)

vensz21@yahoo.com December 19th, 2011 03:16 AM

list view to text boxes!!
 
do you know that code for every time i click the list box it will automatically go to the text box?? for example i click the first index and all of the information will automatically go to textboxes here is my code i think i have mistaken something here bcz evertime i click the index of the list view its not updating the textbox. .
any suggestions?


__________________________________________________ _______________
Public Class Form1
Inherits System.Windows.Forms.Form
Dim nCon As New SqlClient.SqlConnection
Dim nCommand As New SqlClient.SqlCommand
Dim nReader As SqlClient.SqlDataReader
Private Sub connect()
On Error Resume Next
nCon.ConnectionString = "workstation id=BEGS-LAPTOP;packet size=4096;integrated security=SSPI;data source=BEGS-LAPTOP;persist security info=False;initial catalog=DB_INTRANET_HRIS"
nCommand.Connection = nCon
nCon.Open()
End Sub
Private Sub filllvwStudentColumnHeaders()
' add a column width 140 and left alignment
lvwStudent.Columns.Add("User ID", 140, HorizontalAlignment.Left)
lvwStudent.Columns.Add("Lastname", 140, HorizontalAlignment.Left)
lvwStudent.Columns.Add("Firstname", 140, HorizontalAlignment.Left)
lvwStudent.Columns.Add("Middle Initial", 140, HorizontalAlignment.Left)
lvwStudent.Columns.Add("User Level", 140, HorizontalAlignment.Left)
lvwStudent.Columns.Add("User Name", 140, HorizontalAlignment.Left)
lvwStudent.Columns.Add("Password", 140, HorizontalAlignment.Left)
End Sub

Private Sub FilllvwStudent()


Call connect()
nCommand.CommandText = "SELECT * FROM tb_user"
nCommand.Connection = nCon
nReader = nCommand.ExecuteReader()
lvwStudent.Items.Clear()

While (nReader.Read())
With lvwStudent.Items.Add(nReader("User_id"))
.SubItems.add(nReader.GetValue(1))
.subitems.add(nReader.GetValue(2))
.subitems.add(nReader.GetValue(3))
.subitems.add(nReader.GetValue(4))
.subitems.add(nReader.GetValue(5))
.subitems.add(nReader.GetValue(6))
End With
End While
End Sub
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

If nCon.State = ConnectionState.Open Then nCon.Close()
nCon.ConnectionString = "workstation id=BEGS-LAPTOP;packet size=4096;integrated security=SSPI;data source=BEGS-LAPTOP;persist security info=False;initial catalog=DB_INTRANET_HRIS"
nCommand.Connection = nCon
Call connect()

lvwStudent.MultiSelect = False
lvwStudent.GridLines = True
lvwStudent.View = View.Details

Call filllvwStudentColumnHeaders()
Call FilllvwStudent()
lvwStudent.Items(0).Selected = True

Call PutToTextboxes()
End Sub
Private Sub PutToTextboxes()
TextBox1.Text = lvwStudent.SelectedItems(0).Text
TextBox2.Text = lvwStudent.SelectedItems(0).SubItems(1).Text
TextBox3.Text = lvwStudent.SelectedItems(0).SubItems(2).Text
TextBox4.Text = lvwStudent.SelectedItems(0).SubItems(3).Text
TextBox5.Text = lvwStudent.SelectedItems(0).SubItems(4).Text
TextBox6.Text = lvwStudent.SelectedItems(0).SubItems(5).Text
TextBox7.Text = lvwStudent.SelectedItems(0).SubItems(6).Tex
End Sub
End Class


All times are GMT -4. The time now is 12:14 PM.

Powered by vBulletin® Version 3.7.0
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
2013 John Wiley & Sons, Inc.