Click here to Skip to main content
15,890,438 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
There are 4 items on my form:
- two listboxes
- one button
- one text box
I have a listbox 'A' with many items and
I need a item in listbox 'B' from listbox 'A'.

The following are the steps I'd like to perform:
1)enter a word or character in a textbox
2)press a button
3)The list appearing in ListBox 'B' should be composed of entries from
ListBox 'A' if these entries start with the string typed in the
Textbox

I need some help in how to get the entries from ListBox 'A' that match the string in the TextBox into ListBox 'B'

Please help me solve this.

Thank you!
Posted
Updated 21-Nov-10 6:10am
v2
Comments
Manfred Rudolf Bihy 21-Nov-10 12:13pm    
Editing, rephrasing for clarity and some typos.

1 solution

Try:
C#
string search = textBox1.Text;
listBox2.Items.Clear();
foreach (string val in listBox1.Items)
    {
    if (val.StartsWith(search))
        {
        listBox2.Items.Add(val);
        }
    }
 
Share this answer
 
Comments
Manfred Rudolf Bihy 21-Nov-10 12:12pm    
Wow! While I was busy rephrasing, editing and deciphering the question. You already spat out the solution.
Nicely done. Have my 5!
Neeil 21-Nov-10 12:15pm    
thank u sir.....

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900