multiselect, multicolumn listbox (1 Viewer)

homer2002

Registered User.
Local time
Today, 20:36
Joined
Aug 27, 2002
Messages
152
Hi,

i'm having a bit of trouble interegating a multicolumn, multiselect listbox


I'm trying to get the bound field and another column from all
the selected items....

Everything is ok, but I can't see how to reference
a row & column (instead of just the row and the bound column being returned)


heres a sample of my code......

(THE lstActiveMember.ItemData(SelectedItem).Column(5) - IS THE WRONG BIT :) )

______

For Each SelectedItem In lstActiveMember.ItemsSelected
MsgBox lstActiveMember.ItemData(SelectedItem) & " - " & lstActiveMember.ItemData(SelectedItem).Column(5)
Next SelectedItem


________

can someone shed some light to how I reference column(5) as the code loops round each selected item..


Cheers Homer
 

workmad3

***** Slob
Local time
Today, 20:36
Joined
Jul 15, 2005
Messages
375
what exactly is wrong? is column 5 not the data item you want? if so, then you are probably in the OBO trap, and should try column 4 instead. Otherwise clarify a bit further
 

homer2002

Registered User.
Local time
Today, 20:36
Joined
Aug 27, 2002
Messages
152
i'm trying to go through a multi select list box with 5 columns....

.... then in Pseudo Code(ish).....

______________________________________________________

FOR EACH SELECTED ITEM IN THE MULTISELECT LISTBOX
MSGBOX "Column 1 = " & listbox.Column(1)
MSGBOX "Column 2 = " & listbox.Column(2)
NEXT SELECTED ITEM

_______________________________________________________


Problem is as far as I can see... the .Column() property always returns the last row selected by the mouse pointer and not each row in the loop.

i'm looking for the correct syntax to look somthing like

______________________________________________________


FOR EACH SelectedRow IN Listbox.ItemsSelected
Msgbox Listbox.ItemData(SelectedRow) & "," & Listbox.ItemData(SelectedRow).Column(5)
NEXT SelectedRow

'(((((to return the bound column and column(5) for each row that is selected)))))

___________________________________

The part that reads....

Listbox.ItemData(SelectedRow).Column(5)

does not work. I need the syntax to return column 5 properly.

Does that make it any clearer?

Cheers homer
 

workmad3

***** Slob
Local time
Today, 20:36
Joined
Jul 15, 2005
Messages
375
Right, i think(from looking through MSDN) that what you want is this

Msgbox Listbox.ItemData(SelectedRow) & "," & Listbox.Column(5, SelectedRow)

but also remember, the columns are 0 indexed, meaning that column(5) is the 6th column
 

homer2002

Registered User.
Local time
Today, 20:36
Joined
Aug 27, 2002
Messages
152
Nice one, cheers

You hit the nail on the head.

Dunno how I missed that... :)
 

workmad3

***** Slob
Local time
Today, 20:36
Joined
Jul 15, 2005
Messages
375
i spend far too much time googling and browsing msdn at times(espc when im meant to be working).
 

Thales750

Formerly Jsanders
Local time
Today, 15:36
Joined
Dec 20, 2007
Messages
2,150
Can anyone tell me why this won't work.

Code:
Set Mydb = DBEngine.Workspaces(0).Databases(0)
Set rs = Mydb.OpenRecordset("tblLocalProcessesMasterList", dbOpenDynaset)

  'make sure a selection has been made
  If Me.lstProcessItemsList.ItemsSelected.Count = 0 Then
    MsgBox "Please Select Item to Add"
    Exit Sub
  End If
  'add selected value(s) to table
  Set ctl = Me.lstProcessItemsList
  For Each varItem In ctl.ItemsSelected
    rs.AddNew
    
    rs!LocalProcessNameID = ctl.ItemData(varItem)
    rs!LocalProcessLocNameID = ctl.ItemData(varItem).Column(1)
    
   
    rs.Update
  Next varItem

rs!LocalProcessNameID = ctl.ItemData(varItem)

works fine.


rs!LocalProcessLocNameID = ctl.ItemData(varItem).Column(1)

produces Error "Object REqired"

Thanks all.
 

Thales750

Formerly Jsanders
Local time
Today, 15:36
Joined
Dec 20, 2007
Messages
2,150
this works:

Code:
rs!LocalProcessLocNameID = ctl.Column(1, varItem)
 

Users who are viewing this thread

Top Bottom