tehon3299
Centurion
How would I pass a string from a form to another form? I want to pass the value of a selected item in a listview to another form. How would this be done?
public sub New(ByVal thetext as string)
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load 'of course you dont have to do it in formload
Dim thetext As String = "hi"
Dim form2 As New Form2(thetext)
form2.Show()
End Sub
Dim texts As String 'Dim some global variable so you can get the passed value
Public Sub New(ByVal thetext As String)
texts = thetext 'get the value or you can use it for whatever you want
End Sub
Dim team As String
Public Sub New(ByVal teamName As String)
team = teamName
End Sub
Private Sub frmRosterView_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim listViewItems As New ListViewItem()
lvwPlayers.View = View.Details
lvwPlayers.GridLines = True
lvwPlayers.Columns.Add("First", 100, HorizontalAlignment.Left)
lvwPlayers.Columns.Add("Last", 100, HorizontalAlignment.Left)
lvwPlayers.Columns.Add("Address", 100, HorizontalAlignment.Left)
lvwPlayers.Columns.Add("City", 100, HorizontalAlignment.Left)
lvwPlayers.Columns.Add("State", 100, HorizontalAlignment.Left)
lvwPlayers.Columns.Add("ZIP", 50, HorizontalAlignment.Left)
Dim mySelectQuery As String = "SELECT * FROM tmPlayerInfo WHERE Team = teamName"
Dim myConnection As New SqlConnection("server=localhost;database=StatKeeper;Trusted_Connection=yes")
Dim myCommand As New SqlCommand(mySelectQuery, myConnection)
myConnection.Open()
Dim myReader As SqlDataReader
myReader = myCommand.ExecuteReader()
While myReader.Read()
listViewItems.Text = myReader.GetValue(2)
listViewItems.SubItems.Add(myReader.GetValue(3))
listViewItems.SubItems.Add(myReader.GetValue(4))
listViewItems.SubItems.Add(myReader.GetValue(5))
listViewItems.SubItems.Add(myReader.GetValue(6))
listViewItems.SubItems.Add(myReader.GetValue(7))
lvwPlayers.Items.Add(listViewItems)
listViewItems = New ListViewItem()
End While
myReader.Close()
myConnection.Close()
End Sub