i have a problem in my code
i can't get the best answer on how to double click the data in the listview and store the value in the textbox in the other form
pls help me.
I am very please for your response
this is for my project..
thank you..

Dani AI

Generated

A reliable pattern is to avoid tightly coupling forms by exposing a small API on the receiving form (a public method or property) and calling that from the ListView handler. That keeps responsibilities clear and avoids directly touching another form's controls. This also addresses the common pitfalls raised earlier by and the direct-assignment idea from while making the flow safer for real apps.

Example: give the target form a simple setter, then find or create the open instance and call it.

' In frmOther
Public Sub SetSelection(ByVal value As String)
    If Me.InvokeRequired Then
        Me.Invoke(Sub() TextBox1.Text = value)
    Else
        TextBox1.Text = value
    End If
End Sub
' In the form that hosts the ListView
Imports System.Linq

Private Sub ListView1_DoubleClick(sender As Object, e As EventArgs) Handles ListView1.DoubleClick
    If ListView1.SelectedItems.Count = 0 Then Exit Sub
    Dim sel = ListView1.SelectedItems(0)
    Dim val As String = If(sel.SubItems.Count > 0, sel.SubItems(0).Text, sel.Text)
    Dim other = Application.OpenForms().OfType(Of frmOther)().FirstOrDefault()
    If other Is Nothing Then
        other = New frmOther()
        other.Show()
    Else
        other.BringToFront()
    End If
    other.SetSelection(val)
End Sub

Alternate approaches: make the list a modal "picker" form that returns a SelectedValue property after ShowDialog, or raise an event from the list form that the main form subscribes to. Troubleshooting notes: always check SelectedItems and SubItems counts before indexing, avoid creating a new receiver when the visible instance should be updated, and ensure UI updates happen on the UI thread. This keeps behavior predictable and reduces NullReference/Index errors.

Recommended Answers

All 3 Replies

What code are you using and where is it going wrong?

How far you did?

If the user double clicks on the first column you can do

Private Sub ListView1_DoubleClick(sender As System.Object, e As System.EventArgs) Handles ListView1.DoubleClick
    Dim lvw As ListView = sender
    Dim item As ListViewItem = lvw.SelectedItems(0)
    frmOther.TextBox1.Text = item.SubItems(0).Text
End Sub

If the ListView has FullRowSelect set to True then the user can click in any column to select that row. Access any other column by

frmOther.TextBox1.Text = item.SubItems(1).Text
frmOther.TextBox1.Text = item.SubItems(2).Text

etc.

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.