i have a project my next task is to display the item selected from my listview to the textbox in the other form
heres my code on the listview

Public Class listemployee

Private Sub listemployee_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
' Create the column headers.
ListView2.Columns.Add("EmployeeID", _
HorizontalAlignment.Left)
ListView2.Columns.Add("LastName", _
HorizontalAlignment.Left)
ListView2.Columns.Add("FirstName", _
HorizontalAlignment.Left)
ListView2.Columns.Add("MiddleName", _
HorizontalAlignment.Right)
ListView2.Columns.Add("Birthday", _
HorizontalAlignment.Left)
ListView2.Columns.Add("Address", _
HorizontalAlignment.Right)
ListView2.Columns.Add("EmailAddress", _
HorizontalAlignment.Right)
ListView2.Columns.Add("Contact#", _
HorizontalAlignment.Right)
ListView2.Columns.Add("CivilStatus", _
HorizontalAlignment.Left)
ListView2.Columns.Add("Religion", _
HorizontalAlignment.Right)
ListView2.Columns.Add("SSSId", _
HorizontalAlignment.Right)

End Sub

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnloaddata.Click
Dim dr As OleDb.OleDbDataReader
ListView2.Items.Clear()


Call connecttodb()
cmd.CommandText = "SELECT * FROM tblemployee ORDER BY EmployeeID"

dr = cmd.ExecuteReader()
'Stop

Do While dr.Read()

Dim new_item As New _
ListViewItem(dr.Item("EmployeeID").ToString)
new_item.SubItems.Add(dr.Item("LastName").ToString)
new_item.SubItems.Add(dr.Item("FirstName").ToString)
new_item.SubItems.Add(dr.Item("MiddleName").ToString)
new_item.SubItems.Add(dr.Item("Birthday").ToString)
new_item.SubItems.Add(dr.Item("Address").ToString)
new_item.SubItems.Add(dr.Item("EmailAddress").ToString)
new_item.SubItems.Add(dr.Item("Contact#").ToString)
new_item.SubItems.Add(dr.Item("CivilStatus").ToString)
new_item.SubItems.Add(dr.Item("Religion").ToString)
new_item.SubItems.Add(dr.Item("SSSId").ToString)

ListView2.Items.Add(new_item)

Loop

Call disconnecttodb()
End Sub

Private Sub ListView2_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles ListView2.Click
txt1.Text = ListView2.SelectedItems.Item(0).Text
End Sub


Private Sub btnselect_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnselect.Click
Dim dr As OleDb.OleDbDataReader

If txt1.Text = ListView2.SelectedItems.Item(0).Text Then
Call connecttodb()
cmd.CommandText = "SELECT * FROM tblemployee ORDER BY EmployeeID"

dr = cmd.ExecuteReader()

Do While dr.Read()
'txtempid.Text = txt1.Text
'txtlast.Text = dr("LastName").ToString
'txtfirst.Text = dr("FirstName").ToString
'txtmid.Text = dr("MiddleName").ToString
'txtaddress.Text = dr("Address").ToString
'dtbday.Text = Format(CDate(dr("Birthday").ToString), "MM/dd/yyyy")
'txtemail.Text = dr("EmailAddress").ToString
'txtcontact.Text = dr("Contact#").ToString
'cbostat.Text = dr("CivilStatus").ToString
'cboreligion.Text = dr("Religion").ToString
'txtsss.Text = dr("SSSId").ToString

Loop
Call disconnecttodb()

End If
End Sub

End Class

the items in the listview should be display in the textboxes in the other form whenever i click select data

help please...

Member Avatar for Unhnd_Exception

An easy way is to create an event in the form your selected the item from and handling the event in the form you want to receive the item from


In class lstEmployee

Public Event DataSelected(ByVal sender As Object, ByVal e As ListViewItem)

When you selected the data raise the event.

RaiseEvent DataSelected(Me, ListViewItem)

In the form you want to receive the Item

Sub New()

    ' This call is required by the Windows Form Designer.
    InitializeComponent()

    ' Add any initialization after the InitializeComponent() call.
    AddHandler myLstEmployeeClass.DataSelected, AddressOf lstEmployee_DataSelected

End Sub

Private Sub lstEmployee_DataSelected(ByVal sender As Object, ByVal e As ListViewItem)
        'Heres the listview item
End Sub

the raiseEvent is syntax error

the items in the listview should be display in the textboxes in the other form whenever i click select data

See if this helps.

Private Sub ListView2_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles ListView2.Click
        If Not ListView2.SelectedItems.Count = 0 Then '// check if item is selected.
            With ListView2.SelectedItems.Item(0)
                Form2.TextBox1.Text = .Text '// column 1.
                Form2.TextBox2.Text = .SubItems(1).Text '// column 2.
                Form2.TextBox3.Text = .SubItems(2).Text '// column 3.
                Form2.TextBox4.Text = .SubItems(3).Text '// column 4.
                '// etc...
            End With
            'Form2.ShowDialog()
        End If
    End Sub

Form2 has 4 TextBoxes for the first few Columns.

Adding more TextBoxes and using the "ListView2.SelectedItems.Item(0).SubItems(#).Text" will get your TextBoxes loaded with the SelectedItem's values.

employeeform.dtbday.Text = Format(CDate(("Birthday").ToString), "MM/dd/yyyy")


Conversion from string "Birthday" to type 'Date' is not valid.

employeeform.dtbday.Text = Format(CDate(("Birthday").ToString), "MM/dd/yyyy")
Conversion from string "Birthday" to type 'Date' is not valid.

employeeform.dtbday.Text = Format(CDate((ListView2.SelectedItems.Item(0).SubItems(4).Text).ToString), "MM/dd/yyyy")
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.