Solved

Search a listview for an item already in the list.

Posted on 2008-11-01
2
248 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 150 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

Revamp Your Training Process

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action.

Question has a verified solution.

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

Suggested Solutions

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…
The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…

734 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