When I click in listview control to send data in specific textbox then show the error.
run time error 380 Invalid property value.

I write this code:

Private Sub LVEmp_ItemClick(ByVal Item As MSComctlLib.ListItem)
With Item
       Me.txtSrNo = .Text
        Me.txtamount.Text = .SubItems(mlngCUST_LAST_IDX)
       Me.txtdate.Text = .SubItems(mlngCUST_LAST_IDX)

           End With
End Sub

Dani AI

Generated

Quick diagnosis and what fixed it here: the crash was caused by reading a ListView subitem with an invalid index (an undeclared numeric constant evaluates to zero, and the classic MSComctl ListView expects real subitem indexes). Declaring the correct index stopped the run‑time 380, and the “both textboxes show the same data” symptom was simply both assignments using the same subitem index — pointed that out earlier. (techshelps.github.io)

Practical, low-effort hardening to avoid this class of bug:

  • Always put Option Explicit at the top of modules so undeclared names cause compile errors rather than silent 0 values.

  • Before you read a subitem, test the collection size. For example (pseudo/VB-style):

    ' at top of module:
    Option Explicit
    
    ' in the click handler:
    If Not Item Is Nothing Then
        If Item.SubItems.Count >= 2 Then
            txtAmount.Text = CStr(Item.SubItems(1))
            txtDate.Text   = CStr(Item.SubItems(2))
        Else
            ' handle missing columns (clear fields or show defaults)
        End If
    End If

    This prevents index-out-of-range or invalid-value attempts at runtime.

If you ever move this code between classic VB (MSComctl) and .NET/WinForms, watch the API and indexing conventions — the .NET ListView/SubItems behavior and indexing differ from the VB6 control, so copy/paste can introduce off‑by‑one bugs. For storing non-display data (IDs) prefer Tag on the ListItem rather than relying on visible text. (learn.microsoft.com)

Debugging checklist: enable Option Explicit, add a breakpoint and inspect Item.SubItems.Count, print the actual numeric index you use, and use meaningful constant names for each column index. These small steps prevent the runtime 380 and the duplicate-field mistake that ran into.

Recommended Answers

All 4 Replies

I forget to declare ........

Private Const mlngCUST_LAST_IDX As Long = 1

the problem was solved. but now problem is: both text box show same data.

now I declare another one like:
Private Const mlngCUST_Date_IDX As Long = 2

problem is: both text box show same data

Of course they do. Your code

Me.txtamount.Text = .SubItems(mlngCUST_LAST_IDX)
Me.txtdate.Text   = .SubItems(mlngCUST_LAST_IDX)

is assigning the same value to both textboxes. C hange it to

Me.txtamount.Text = .SubItems(mlngCUST_LAST_IDX)
Me.txtdate.Text   = .SubItems(mlngCUST_DATE_IDX)
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.