Click here to Skip to main content
15,886,110 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am trying to implement a suggested list from a comboBox written by Vinh Nguyễn Toàn Create combobox with search and suggest list[^]
I have a linkedlist:
private LinkedList<string> AllProjects = new LinkedList<string>();

On entering a value into the comboBox:-
private void comboBoxProjects2_KeyPress(object sender, KeyPressEventArgs e)
{
    if (Convert.ToInt32(e.KeyChar) == 13)
    {
        Cursor = Cursors.WaitCursor;
        string textToSearch = comboBoxProjects2.Text.ToLower();
        listBox1.Visible = false;
        if (String.IsNullOrEmpty(textToSearch))
        {
            return;
        }
        string[] result = (from i in AllProjects where i.ToLower().Contains(textToSearch) select i).ToArray();
        if (result.Length == 0)
        {
            return;
        }
        listBox1.Items.Clear();
        listBox1.Items.AddRange(result);
        listBox1.Visible = true;
        Cursor = Cursors.Default;
    }
}

The code hangs on the "string[] result =....." line.

What I have tried:

Tried to get a better understanding of LinkedList searches.
Looked for other ways of achieving the same result, all too slow.
Posted
Updated 19-Dec-21 11:41am

1 solution

I find it unlikely that it "hangs" on this line:
string[] result = (from i in AllProjects where i.ToLower().Contains(textToSearch) select i).ToArray();
Unless AllProjects contains a humongous number of strings it it requires massive amounts of disk paging to support the entire search - which is very unlikely.
Admittedly, a considerable number of string searches would take considerable time, but with modern equipment it shouldn't hang - and a major fault in a 15 year old class is very unlikely.

So I'd start by looking at how you are sure it's that line that causes the problem - is it via the debugger or some "other way"?
What does the debugger show the linked list looks like? Are the forward and backward links OK? And so forth.

It's more likely to be other code like an update event on your listbox that causes the problem.
 
Share this answer
 
Comments
ormonds 19-Dec-21 17:59pm    
Thank you - a closer look at the linked list showed errors in that.
OriginalGriff 20-Dec-21 1:26am    
You're welcome!

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