Solved

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

Posted on 2004-10-01
4
1,587 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
4 Comments
 
LVL 14

Assisted Solution

by:ptakja
ptakja earned 65 total points
ID: 12201726
Try  

ListBox1.SelectedItem = strLine
0
 
LVL 96

Accepted Solution

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

Bob
0
 

Author Comment

by:nchantim
ID: 12217762
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

Enroll in June's Course of the Month

June's Course of the Month is now available! Every 10 seconds, a consumer gets hit with ransomware. Refresh your knowledge of ransomware best practices by enrolling in this month's complimentary course for Premium Members, Team Accounts, and Qualified Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

If you're writing a .NET application to connect to an Access .mdb database and use pre-existing queries that require parameters, you've come to the right place! Let's say the pre-existing query(qryCust) in Access takes a Date as a parameter and l…
Introduction As chip makers focus on adding processor cores over increasing clock speed, developers need to utilize the features of modern CPUs.  One of the ways we can do this is by implementing parallel algorithms in our software.   One recent…
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …

707 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