listbox select different item

03-11-2006, 01:46 PM
Been digging up great information out of these boards but I was hoping to get a hint - how to choose a specific item within a listbox from code.

I'm actually doing the below - just attempting to add buttons to allow the user to re-order items within the listbox - this works but the selected index stays with the original index - not the new position.

I'd tried changing the order of which field I'd updated hoping that would do it without any impact...and yes, I realize this is probal

Dim itemPos As Long
Dim strVal As String

itemPos = Me.lboSeletedColumns.Items.IndexOf(Me.lboSeletedColumns.Text)
If itemPos > -1 And itemPos < Me.lboSeletedColumns.Items.Count() - 1 Then
strVal = Me.lboSeletedColumns.Items(itemPos) 'copy to temp variable
Me.lboSeletedColumns.Items(itemPos) = Me.lboSeletedColumns.Items(itemPos + 1)
Me.lboSeletedColumns.Items(itemPos + 1) = strVal
End If

Ack - no need to answer. I searched for 30 minutes, and then tried one more time after posting and found my answer.

Me.lboSeletedColumns.SelectedIndex = itemPos + 1

Could have sworn I'd tried that earlier.


EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum