Link to home
Start Free TrialLog in
Avatar of nchantim
nchantim

asked on

"Winforms ListItem" - or "how to Select items in a Listbox"

I'm going batty trying to programatically highlight items allready in  a listbox in a windows app.
I temporarily discovered ListItem, only to realize it's a webforms thing.

What I want it something like this, but that works in a windows app:

Sub HighlightItem (strLine)
    Dim lstObj as ListItem
    For Each lstObj In Me.lstInstrumentTypes.Items
        If lstObj.Text = strLine Then
            lstObj.Selected = True
        End If
    Next
End Sub

Yes, I know about the ListView control.

SOLUTION
Avatar of ptakja
ptakja
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
ASKER CERTIFIED SOLUTION
Avatar of Bob Learned
Bob Learned
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of nchantim
nchantim

ASKER

Thanks, but the problem here is I'm using Multiextended, and have several items that I need to highlight.

I tried my code with the listbox, but of course, ListItem is in Web.UI.WebControls.ListItem, not in Windows.Forms namespace
and Vb.net  seems to dislike trying to convert the type.

I think I may end up using a ListView in Details mode - that seems to work quite well after all.
Oddly enough, I've been using VB since v3, and never had a program try to highlight a list box item before!