Solved

Search a ListView using Selected ComboBox Value

Posted on 2009-07-09
5
978 Views
Last Modified: 2012-05-07
I need to search a listview, highlight the found value and display the result in textboxes using the selected value from a ComboBox.
0
Comment
Question by:wsenter
5 Comments
 
LVL 2

Expert Comment

by:pr_r
ID: 24820334
Can u be bit eloborate.
if you have tried it can u paste the code also.
0
 
LVL 1

Author Comment

by:wsenter
ID: 24820348
I have a form with a listview control that is populated with CustomerID, CustomerName. I have a combo box on the form that is filled with the same information.  I am using suggest/append setting on the combo box for the user to search for the customer. When they find the customer, they press tab for example. Then, take the CustomerID from the combo box and lookup the matching entry in the listview. highlight the listview selection, lookup the record and display in text fields.

Thanks
0
 
LVL 2

Expert Comment

by:lppperes
ID: 24820364
You can try something like this:

    Private Sub Form2_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        For index As Integer = 1 To 10
            ComboBox1.Items.Add(index.ToString())
            ListBox1.Items.Add(index.ToString())
        Next
    End Sub

    Private Sub ComboBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ComboBox1.SelectedIndexChanged
        Dim text As String = ComboBox1.SelectedItem.ToString()
        Dim index As Integer = ListBox1.FindStringExact(text)
        If index <> 0 Then
            ListBox1.SelectedIndex = index
            TextBox1.Text = ComboBox1.SelectedItem.ToString()
        End If
    End Sub
0
 
LVL 15

Accepted Solution

by:
angus_young_acdc earned 500 total points
ID: 24821265
The following C# code will do what you're looking for based upon whatever combobox ID you have selected:
private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)

        {

            // Loop through the list view checking the first subitem (which is your first column

            foreach (ListViewItem item in listView1.Items)

            {

                if (item.SubItems[0].Text == comboBox1.Text)

                {

                    item.Selected = true;

                    textBox1.Text = item.SubItems[0].Text; // your customer id

                    textBox2.Text = item.SubItems[1].Text; // Your customer name

                }

            }

        }

Open in new window

0
 
LVL 1

Author Closing Comment

by:wsenter
ID: 31601941
Excellent Bud!
0

Featured Post

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

Extention Methods in C# 3.0 by Ivo Stoykov C# 3.0 offers extension methods. They allow extending existing classes without changing the class's source code or relying on inheritance. These are static methods invoked as instance method. This…
Article by: Najam
Having new technologies does not mean they will completely replace old components.  Recently I had to create WCF that will be called by VB6 component.  Here I will describe what steps one should follow while doing so, please feel free to post any qu…
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

743 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

12 Experts available now in Live!

Get 1:1 Help Now