Solved

Search a listview for an item already in the list.

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

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
update textboxes with Streamreader 21 47
Variable Event ? 3 27
How to sort a list of objects using an item in an enclosed list 5 46
Expression Evaluater 3 24
Since .Net 2.0, Visual Basic has made it easy to create a splash screen and set it via the "Splash Screen" drop down in the Project Properties.  A splash screen set in this manner is automatically created, displayed and closed by the framework itsel…
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…
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

776 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