?
Solved

Search a ListView using Selected ComboBox Value

Posted on 2009-07-09
5
Medium Priority
?
985 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 2000 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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

Summary: Persistence is the capability of an application to store the state of objects and recover it when necessary. This article compares the two common types of serialization in aspects of data access, readability, and runtime cost. A ready-to…
This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …
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…
Suggested Courses

777 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