Wrox Programmer Forums
|
VB.NET 2002/2003 Basics For coders who are new to Visual Basic, working in .NET versions 2002 or 2003 (1.0 and 1.1).
Welcome to the p2p.wrox.com Forums.

You are currently viewing the VB.NET 2002/2003 Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old December 19th, 2011, 04:16 AM
Registered User
 
Join Date: Dec 2011
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default 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





Similar Threads
Thread Thread Starter Forum Replies Last Post
Help with List Boxes Jewel142 BOOK: Visual Basic 2010 Programmer's Reference 4 April 5th, 2011 08:43 AM
Displaying data in a tree view from combo boxes Gini Visual Studio 2008 0 June 25th, 2008 01:52 AM
Help Grid View Drop Down List, view all jskinner123 ASP.NET 2.0 Basics 0 November 25th, 2007 06:25 PM
populate details view or list view non empty rows iinfoque ASP.NET 2.0 Basics 0 March 11th, 2007 06:11 AM
SQL , List Boxes/Menu Boxes, DB's Ginzu3 Classic ASP Databases 1 June 30th, 2003 04:07 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.