?
Solved

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

Posted on 2004-10-01
4
Medium Priority
?
1,617 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
3 Comments
 
LVL 14

Assisted Solution

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

ListBox1.SelectedItem = strLine
0
 
LVL 96

Accepted Solution

by:
Bob Learned earned 180 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

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

Microsoft Reports are based on a report definition, which is an XML file that describes data and layout for the report, with a different extension. You can create a client-side report definition language (*.rdlc) file with Visual Studio, and build g…
Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
Loops Section Overview
With just a little bit of  SQL and VBA, many doors open to cool things like synchronize a list box to display data relevant to other information on a form.  If you have never written code or looked at an SQL statement before, no problem! ...  give i…
Suggested Courses

807 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