-
I wrote some code to add file names to a list box for program i'm working on, there are 2 colums one for the file name one for the file's path, similar to vb open project(recent tab) dialog box.
When I add a item and set it's selected property to tru it doesn't show up hight lighted. The only way I can highlight a item is to select it via mouse.
How can I slected the newly added property, so that it actually shows up selected to the user.
Please help...Thanks!!!
-
It should work
Try setting fullrowselect to true
He's my code that worked
Private Sub cmdFind_Click()
m_strCurrentProcedure = "cmdFind_Click"
On Error GoTo ErrorHandler
Dim intIndex As Integer
Dim intTotalItems As Integer
Dim ltiItem As ListItem
If m_strSearchKey = "Account" Then 'search for the account (subitem 1)
Set ltiItem = lvwDebtors.FindItem(txtFind, 1, 1, lvwPartial)
Else 'search for a name
'Unfortunatly we can only do partial searchs on the item.text not the subitem.text
'This means we have to put the name we are searching for into the listitem.text before we can search
intTotalItems = lvwDebtors.ListItems.Count
For intIndex = 1 To intTotalItems
lvwDebtors.ListItems(intIndex).Text = lvwDebtors.ListItems(intIndex).SubItems(2)
Next intIndex
'Now search on the text we just created
Set ltiItem = lvwDebtors.FindItem(txtFind, , , lvwPartial)
'Now remove the text strings
For intIndex = 1 To intTotalItems
lvwDebtors.ListItems(intIndex).Text = ""
Next intIndex
End If
'Now select the item
ltiItem.Selected = True
lvwDebtors.SelectedItem.EnsureVisible
lvwDebtors.HideSelection = False
Exit Sub
ErrorHandler:
'inform the user that the item was not found
Dim errNum
errNum = Err.Number
If errNum = 91 Then
MsgBox "Sorry, the customer was not found", , "Customer Not Found"
txtFind = ""
txtFind.SetFocus
Exit Sub
Else
MsgBox Err.Number & " - " & Err.Description & vbCrLf & "An error occurred in " & m_CurrentModule & "." & m_strCurrentProcedure & vbCrLf & "Please see the vendor."
End If
End Sub
-
Code:
List1.Selected(0) = True