[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

Search a ListView using Selected ComboBox Value

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

[Webinar] Lessons on Recovering from Petya

Skyport is working hard to help customers recover from recent attacks, like the Petya worm. This work has brought to light some important lessons. New malware attacks like this can take down your entire environment. Learn from others mistakes on how to prevent Petya like worms.

Question has a verified solution.

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

Article by: Ivo
C# And Nullable Types Since 2.0 C# has Nullable(T) Generic Structure. The idea behind is to allow value type objects to have null values just like reference types have. This concerns scenarios where not all data sources have values (like a databa…
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…
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
Suggested Courses

649 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