Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Search a listview for an item already in the list.

Posted on 2008-11-01
2
Medium Priority
?
250 Views
Last Modified: 2012-06-22
Hi All,

I am using a KeyPress event to place the textbox.text into the listbox but only if it does not exist. It just keeps adding the same named item even though it is in the list, probably something simple. Here is my code:
If e.KeyChar = Microsoft.VisualBasic.ChrW(Keys.Return) Then
            Dim strg As String = txtAddUnit.Text
            Dim item As ListView.ListViewItemCollection = ltvUnits.Items
            Dim index As Integer
            If ltvUnits.Items(index).Text = strg Then
                Exit Sub
            Else
                ltvUnits.Items.Add(strg).BackColor = Color.LightGreen
                UnitTrackingPanel2()
                txtAddUnit.Text = String.Empty
            End If
        End If

Open in new window

0
Comment
Question by:Hawkvalley1
[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
2 Comments
 
LVL 47

Accepted Solution

by:
Wayne Taylor (webtubbs) earned 600 total points
ID: 22859847
try this...
    Private Sub txtAddUnit_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles txtAddUnit.KeyPress
        If e.KeyChar = Microsoft.VisualBasic.ChrW(Keys.Return) Then
            If ltvUnits.FindItemWithText(txtAddUnit.Text) Is Nothing Then
                ltvUnits.Items.Add(txtAddUnit.Text).BackColor = Color.LightGreen
                UnitTrackingPanel2()
                txtAddUnit.Text = String.Empty
            End If
        End If
    End Sub

Open in new window

0
 
LVL 9

Author Closing Comment

by:Hawkvalley1
ID: 31512429
Thanks again...
0

Featured Post

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

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

Article by: Kraeven
Introduction Remote Share is a simple remote sharing tool, enabling you to see, add and remove remote or local shares. The application is written in VB.NET targeting the .NET framework 2.0. The source code and the compiled programs have been in…
Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
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: …
Want to learn how to record your desktop screen without having to use an outside camera. Click on this video and learn how to use the cool google extension called "Screencastify"! Step 1: Open a new google tab Step 2: Go to the left hand upper corn…
Suggested Courses

688 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