ListView DblClick on Event to get Values

Rex2024

New Member
Joined
Nov 17, 2022
Messages
32
Office Version
  1. 365
Platform
  1. Windows
I have a listview in a userform and want to be able to double click on the event and populate the data in both caption and value fields.

I am struggling with the code. This is one of the items that it supposed to work, but doesn't seem to be doing so.

VBA Code:
Private Sub ListView1_DblClick
Dim TheSelectedItem As ListItem
If Me.ListView1.SelectedItems.Count > 0 Then
TheSelectedItem = Me.ListView1.SelectedItems(0)
Me.TextBox1.Text = TheSelectedItem.Text
Me.TextBox2.Text = TheSelectedItem.SubItems(0).Text
Me.TextBox3.Text = TheSelectedItem.SubItems(1).Text
End If
End Sub
 

Excel Facts

How can you automate Excel?
Press Alt+F11 from Windows Excel to open the Visual Basic for Applications (VBA) editor.
Hi Rex2024

Try this ;)
VBA Code:
Private Sub ListView1_DblClick()
    With Me.ListView1
      If .SelectedItem <> "" Then
        Me.TextBox1.Text = .SelectedItem.Text
        Me.TextBox2.Text = .SelectedItem.ListSubItems(1).Text
        Me.TextBox3.Text = .SelectedItem.ListSubItems(2).Text
      End If
    End With
End Sub
 
Upvote 0
Solution
Works as intended with a little maneuvering for my specific needs. Thank you so much!
 
Upvote 0

Forum statistics

Threads
1,215,096
Messages
6,123,074
Members
449,093
Latest member
ripvw

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top