Solved

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

Posted on 2004-10-01
4
1,570 Views
Last Modified: 2012-08-14
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.

0
Comment
Question by:nchantim
4 Comments
 
LVL 14

Assisted Solution

by:ptakja
ptakja earned 65 total points
Comment Utility
Try  

ListBox1.SelectedItem = strLine
0
 
LVL 96

Accepted Solution

by:
Bob Learned earned 60 total points
Comment Utility
What happens when you use the code with the ListBox?  And does SelectionMode = One or MultiExtended?

Bob
0
 

Author Comment

by:nchantim
Comment Utility
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!
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

This article explains how to create and use a custom WaterMark textbox class.  The custom WaterMark textbox class allows you to set the WaterMark Background Color and WaterMark text at design time.   IMAGE OF WATERMARKS STEPS Create VB …
Well, all of us have seen the multiple EXCEL.EXE's in task manager that won't die even if you call the .close, .dispose methods. Try this method to kill any excels in memory. You can copy the kill function to create a check function and replace the …
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

744 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now