All pastes #654247 Raw Edit

Robert

public text v1 · immutable
#654247 ·published 2007-08-12 06:58 UTC
rendered paste body
This works to search in the searchbox and display the found result in the ListBox:

        private void txtSearch_TextChanged(object sender, System.EventArgs e)
        {

            // clear the results list
            lstResults.Items.Clear();

            // check to see if search box is empty
            if (txtSearch.Text != "")
            {
                foreach (Contact contact in addressBk)
                {
                    int len = txtSearch.Text.Length;

                    if (contact.LastName.Length >= len && string.Compare(contact.LastName.Substring(0, len), txtSearch.Text, true) == 0)
                    {
                           lstResults.Items.Add(contact.LastName);
                    }
                }
            }
        }

But this part I'm working on doesn't:

        private void displayAddressBookToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (lstResults.SelectedIndex != -1)
            {
                foreach (Contact contact in addressBk)
                {
                    lstResults.Items = contact.LastName; // I know this is wrong but I've tried lstResults.Items.Add(contact.LastName); with no errors but no results either
                      
                }
                
            }
        }