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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

supporting second column in listbox objects 1

Status
Not open for further replies.

raileyb

Programmer
Apr 9, 2005
13
US
Hi,
I have this code in place in a on click event.
It moves the selected items from one list into another list.
But I want to alter it so that both this list and the target list have two columns (the second column being invisible on the form and containing a reference value that I will use in my code.)

Can someone tell me how I can alter this code?

If I merely alter the strval assignment to add a value after the existing ;, then that value shows up as a second value in the target object. I think I'm needing help with the syntax and possibly the correct properties for the target object.
Thanks

Dim ctl As Control
Dim varItm As Variant
Dim strVal As String
Dim strItems As String
Set ctl = Me!lstFindings
For Each varItm In ctl
'For Each varItm In ctl.ItemData
strVal = strVal & ctl.ItemData(varItm) & "; "
Next

ListSystemImpactedSelected.RowSourceType = "Value List"
ListSystemImpactedSelected.RowSource = strVal
 
Not totally sure how this is suppose to function, but I see some problems. The "itemData" property is not a collection as far as I know, so I do not think the For next loop will work, but this does:
Code:
  Dim counter As Integer
  For counter = 0 To (CmboTest.ListCount - 1)
    debug.print cmboTest.ItemData(counter)
  Next counter
Your target will have to have 2 columns so set, and my guess is that you did not do this.
cmboTest.columncount = 2
To make column 2 invisible set its width to zero
cmboTest.columnwidths = "1;0"
Now the even numbered entries in your row source string will go into column two:
"firstColumn";"secondColumn";"firstcolumnSecondRow";"secondColumnSecondRow"

I hope this helps
 
Thanks for the reply.
I believe I corrected tried what you suggest prior to posting. I may have either incorrectly attempted what you're suggesting or maybe the key is my definition of the itemData object.

I do know that as the code is now, it works and I process the list when it's 'finalized' by the user by going thru each record and inserting it successfully into a table. But I may just be getting lucky with the current definition.

I'll be looking at everything more today.

As always, I am very grateful for the technical responses and support I receive from this forum and will apply a star to your post if it proves helpful!

thanks again,
Taz
 
Have a look at the ItemsSelected collection and the Column property of the ListBox object.

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
Thank you for your help.
I am now able to populate and hide a second column.
IF my target object is named ListSystemImpactedSelected,
and i wanted to see the separate column values while running in debug, how would I reference the individual columns?

taz
 
Again, play with the Column(col#,row#) property.

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
Hi,
I have form that contains two listboxs.
The first listbox (lstfindings) is populated with the results of a query so the user can see a set of findings that they can then click on (multiselect), selecting just the subset of this list.
I have an on click event on this first listbox. Each time the user clicks on an item the following code runs.

The original purpose of the code was to populate the second listbox object (ListSystemImpactedSelected) with the items the user selects from the first listbox.
It was running and executing fine.

However, I needed to alter the second listbox, adding a second column (with a width of zero so the user wouldn't see it).
My new intention is to build the list as before, but then loop thru the second listbox values, pulling off and storing into a table not only the visible column the user selects, but also the hidden value.
(The original table store had to be altered to support 'sections' like a,b,c,d because the final step is to load various objects of a report with this value.)

I have tried (hours) of different scenerios, clearly something either in my object definitions or my actual assignment of values is wrong.
Looking up references and code examples has not helped (four hours and counting).

Debug output from the following code gives me the value of 'a' for Tctl.ItemData(counter)
If I click on two items from the original list,
debug.print Tctl.listcount gives me a value of 2
But I have no why of extracting the actual data values.
strVal has a value of "'Aortic motion: not assessed';'a';'Pulmonic motion: not assessed';'a';"
Where the user selected:
Aortic motion: not assessed
Pulmonic motion: not assessed
and I added 'a' as the second column value.

Can someone with a sharp eye and a patient mind look at this code.
Thank you,
Taz

Private Sub lstFindings_Click()
Dim ctl As Control
Dim Tctl As Control
Dim varItm As Variant
Dim strVal As String
Dim strItems As String
Set ctl = Me!lstFindings
Dim counter As Integer

'the original intention of this loop
'was to rebuild the string strVal each time an item is selected or deselected from the
'first listbox.
'It has worked from day one for that.
For Each varItm In ctl.ItemsSelected
'strVal = strVal & ctl.ItemData(varItm) & ";"
'added second value as test to see if hidden column in new, two column listbox can be populated.
strVal = strVal & ctl.ItemData(varItm) & ";a;"
Next

ListSystemImpactedSelected.RowSourceType = "Value List"
ListSystemImpactedSelected.RowSource = strVal
'added this sometime during the hours of debugging, trying to get this to work with the new goal.
ListSystemImpactedSelected = strVal

Set Tctl = Me!ListSystemImpactedSelected
For counter = 0 To (Tctl.ListCount - 1)
Debug.Print Tctl.ItemData(counter)
Next counter

End Sub
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top