Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Showing ItemData of List

Status
Not open for further replies.

Jefftopia

Programmer
Jul 30, 2002
104
0
0
US
I have a listbox which is loaded using a columnar formatted string. When I load the list box, I set the ItemData property of each row to a specific numeric identifier.

All is working well, but I would like it if I could see that numeric identifier whenever I DblClick for respective row.

In other words, how can I access the ItemData identifier on DblClick event procedure?
 
I think this what you are looking for

Option Explicit

Private Sub Form_Load()
Dim i As Long

For i = 1 To 10
List1.AddItem "List Item " & CStr(i)
List1.ItemData(i - 1) = i * i
Next
End Sub

Private Sub List1_DblClick()
Me.Caption = List1.ItemData(List1.ListIndex)
End Sub

Let me know if this helps. If you choose to battle wits with the witless be prepared to lose.
[machinegun][hammer]

[cheers]
 
Try this:

Private Sub List1_DblClick()
MsgBox List1.ItemData(List1.ListIndex)
End Sub

________________________________________________________________
If you want to get the best response to a question, please check out FAQ222-2244 first

'People who live in windowed environments shouldn't cast pointers.'
 
I keep getting a return of 0 in the message box when i use:

Private Sub List1_DblClick()

MsgBox List1.ItemData(List1.ListIndex)

End Sub

Here is how I am populating ItemData. It seems to be working:

i = 0

Do Until MySet.EOF

'Build columnar formatted string.
MyStr = MySet!Type
MyStr = MyStr & Chr$(9) & MySet!Vehicle
MyStr = MyStr & Chr$(9) & MySet!Issuer
MyStr = MyStr & Chr$(9) & MySet!Facility
MyStr = MyStr & Chr$(9) & MySet!Amount
MyStr = MyStr & Chr$(9) & MySet!Price
MyStr = MyStr & Chr$(9) & MySet!Analyst
MyStr = MyStr & Chr$(9) & MySet!Submit_time

'Add MyStr to MH3DListBox; set item data to Comp_id.
List1.ItemData(i) = MySet.Fields("Comp_id")
List1.List(i) = MyStr

MySet.MoveNext

i = i + 1

Loop

 
Is it possible that MySet.Fields("Comp_id") is being read as a string, and not as numeric? Since ItemData can only be a number, it would not store correctly. Try forcing as a numeric value like this:

List1.ItemData(i) = CLng(MySet.Fields("Comp_id"))

Robert
 
As Foada says, I believe you need to use the AddItem method to put the ListItem in, then put the ItemData in after generating the ListItem.
________________________________________________________________
If you want to get the best response to a question, please check out FAQ222-2244 first

'People who live in windowed environments shouldn't cast pointers.'
 
Your Code is:
'Add MyStr to MH3DListBox; set item data to Comp_id.
List1.ItemData(i) = MySet.Fields("Comp_id")
List1.List(i) = MyStr

Change it to
'Add MyStr to MH3DListBox; set item data to Comp_id.
List1.List(i) = MyStr
List1.ItemData(i) = MySet.Fields("Comp_id")

You must issue List1.List or List1.additem first before you can pass a value to List1.ItemData. I think you issue a On Error Resume Next in you procedure that's why you didn't encounter an error message. Try to remove that code and you will see what i'm talking about.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top