|
-
August 3rd, 2004, 10:22 AM
#1
ListBox
Hi All,
I have loaded the fields from a table into a listbox, but the problem is with the index. when I try to reference the index it gives me the wrong one. I have relationship between the two tables. I set the listbox's index into the one in the table and referencing the new index but it doesn't work.
Can somebody please help me
-
August 3rd, 2004, 10:31 AM
#2
You could use a ListView. In a list view, every item has a Tag property. You can save the item's index in the table into the Tag property. Never assume the index of the item in the table is the same as the index of the item in the ListBox or ListView.
If you don't want to use a ListView, you could emulate a Tag property by having an array which holds the indeces of the items in the list box.
-
August 3rd, 2004, 10:41 AM
#3
 Originally Posted by nkagi
Hi All,
I have loaded the fields from a table into a listbox, but the problem is with the index. when I try to reference the index it gives me the wrong one. I have relationship between the two tables. I set the listbox's index into the one in the table and referencing the new index but it doesn't work.
Can somebody please help me
I'm not convinced youre using Index in the right way.. Index, when talking of Listbox, is used to identify which control we are talking about, in an array of controls..
Avoid using Tag too, because that is the data for that Listbox control, not for each item inside of it.
Have a look at the simple code from a project of mine:
Code:
Public Sub populate()
findNextItemNumber
List1.Clear
'i wrote a class module called PreparedStatement so to make DB
'interactions like that in java - ignore this part, all we care about
'is the result set, adoRS
ps.prepareStatement DB_SELECT
Set adoRS = ps.executeQuery
'are there actually any reasons there?
If adoRS.EOF Then
List1.AddItem "No editable reasons"
List1.AddItem "were found. You may"
List1.AddItem "only use the Add"
List1.AddItem "facility."
List1.Enabled = False
cmdCancel_Click
Exit Sub
End If
List1.Enabled = True
'yes? then add them to the list
Dim itemDataCounter As Integer
itemDataCounter = 0
Do Until adoRS.EOF
List1.AddItem adoRS!ParaDescription
'here look! :)
List1.ItemData(itemDataCounter) = CLng(adoRS!ParaCode)
itemDataCounter = itemDataCounter + 1
adoRS.MoveNext
Loop
'reset everything by pretending to click on cancel
cmdCancel_Click
End Sub
it populates a list box, and each item in the list shows some text, but that item has an autonumber primarty key, and i want to keep that primary key accessible, but hide from the user's eyes, so i put it in the itemdata property.. every item in a list has its own itemdata property, and it's "as Long " type
-
August 3rd, 2004, 10:44 AM
#4
Yeah, I forgot about the ItemData property.
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
|