Solved

Search a ListView using Selected ComboBox Value

Posted on 2009-07-09
5
984 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
[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
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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Introduction This article series is supposed to shed some light on the use of IDisposable and objects that inherit from it. In essence, a more apt title for this article would be: using (IDisposable) {}. I’m just not sure how many people would ge…
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
There are cases when e.g. an IT administrator wants to have full access and view into selected mailboxes on Exchange server, directly from his own email account in Outlook or Outlook Web Access. This proves useful when for example administrator want…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…

689 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