Solved

Search a listview for an item already in the list.

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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

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…
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…
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

760 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

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now