Select a record in multiple column listbox.

calvinle

Registered User.
Local time
Today, 02:39
Joined
Sep 26, 2014
Messages
332
Hi,

How do I force a listbox to select a record that has 2 columns?

Here is what I am using when the listbox has 1 column:
Code:
      For iList = 0 To Me.lboClient.ListCount
        Me.lboClient = Me.lboClient.ItemData(Me.txtlboClientId + 1)
      Next iList
But it doesn't work when that listbox has 2 columns.

I tried this, but it's not working:
Code:
      For iList = 0 To Me.lboClient.ListCount
        Me.lboClient = Me.lboClient.ItemData(Me.txtlboClientId + 1) & "," & Me.lboClient.Column(1, Me.txtlboClientId + 1)
      Next iList

I cannot use the:
Code:
        Me.lboClient.Selected(Me.txtlboClientId)
as this code only capture the selected item but does not iterate through it.

Thanks
 
I'm confused; you select based on the bound column so I'd expect the same method to work. What does the textbox contain? You can loop the listbox and select based on the value.
 
When I bound that listbox to 1 column, then it will work. But when I bound to 2 column, it doesnt not.

Strange..
 
Youe code for 1 column will work with multiple column since only 1 column can be ound to the combo/listbox.
 
I think it's better I post a video.
See the 2nd listbox, it works. When I try to move to another selection, and I click no, it brings back to the previous selection.
In the last part, when I try to move to another selection (the 1st listbox), after I press no, it takes to the first selection which is wrong. It should take to the 3rd selection as per the textbox (3).

See attachment.
 

Attachments

I think I know the issue. Since the listbox data has 2 same value, it will take the first one. "1PD" which make sense. How can I make the code to select the value of the listbox base on the 1st column and 2nd column?

Thanks
 
I dont understand what your issue is but have you tried using the column property?

me.MylistBox.Column(0) or me.MylistBox.Column(1)

note the column property is zero based so the first column is 0, the second is 1, etc.
 
For listboxes and combos to work correctly, you MUST have a unique identifier. Believe it or not, this is the reason I moved away from natural keys which frequently require multiple fields for uniqueness to autonumbers.
 

Users who are viewing this thread

Back
Top Bottom