|
-
Sep 10th, 2001, 07:58 AM
#1
Thread Starter
New Member
Sorted Listbox loses Itemdata
I'm using some listboxes which contain a string value as well as an itemdata which is storing the ID from a database.
My problem is, when the listbox.sorted = true, the itemdata is lost when I try to get it based on the listindex. ie, lstBox.itemdata(lstBox.listindex))
The sorted property of the listbox can only be set at design time. I can't find a way around this except to use a third party control such as VSFlexGrid.
-
Sep 10th, 2001, 08:01 AM
#2
PowerPoster
Hi
Use List1.ItemData(List1.NewIndex) instead when adding items to ur sorted list box.
Regards
Stuart
-
Sep 10th, 2001, 08:13 AM
#3
Thread Starter
New Member
Didn't work
BeachBum,
Thanks for your help -- but I don't think that works. The itemdata are lost as soon as the .additem looping is finished (because the list is sorted). I tried what you suggested, but it didn't work because there are many items in the listbox which I then need the itemdata for when they are clicked on.
Any other suggestions? I wish the .sorted property could be set at run time, that would fix it I think.
-
Sep 10th, 2001, 08:24 AM
#4
Try setting the .Sorted property to False, and sort the recordset the populates the listbox.
In otherwords,
SQL = "SELECT * FROM tablename ORDER BY whatever "
Create recordset based on SQL statement.
Send the sorted recordset through the List1.Additem loop
-
Sep 10th, 2001, 08:24 AM
#5
PowerPoster
Hi
Well am not sure how u are using then cos it does keep the correct itemdata when u use newindex.
Try this and then adapt for ur needs
Regards
Stuart
VB Code:
Option Explicit
'1 command button, 1 listbox and 1 label on form
Private Sub Command1_Click()
With List1
.AddItem "z"
.ItemData(.NewIndex) = 1
.AddItem "a"
.ItemData(.NewIndex) = 2
.AddItem "g"
.ItemData(.NewIndex) = 3
End With
End Sub
Private Sub List1_Click()
With List1
Label1.Caption = .List(.ListIndex) & " " & .ItemData(.ListIndex)
End With
End Sub
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|