?
Solved

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

Posted on 2004-10-01
4
Medium Priority
?
1,595 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 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

Introducing Priority Question

Increase expert visibility of your issues by participating in Priority Question, our latest feature for Premium and Team Account holders. Adjust the priority of your question to get emergent issues in front of subject-matter experts for help when you need it most.

Question has a verified solution.

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

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 …
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…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…
Suggested Courses
Course of the Month14 days, 16 hours left to enroll

771 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