1
Answer

listbox change button.

Song Lee

Song Lee

9y
663
1
Hello, I'm trying to set up something that user can use to change listbox content, but I'm getting errors:
1) 'contactIn' is a variable but is used like a method
2) No overload for method "ChangeContact" takes 1 arguments


ContactManager Class

class
 ContactManager
{
     private List<Contact> m_contactRegistry; //declare object of the collection
     public ContactManager()
     {
           m_contactRegistry = new List<Contact>();
     }


  /// <summary>
        /// Changes selected item
        /// </summary>
        /// <param name="index"></param>
        /// <param name="contactIn"></param>
        /// <returns></returns>


        public bool ChangeContact(string str, Contact contactIn)
        {
            foreach (Contact c in m_contactRegistry)
            {
                if (c.ToString() == str)
                {
                    m_contactRegistry = contactIn(c);
                    return true;
                }
            }
            return false;
        }



 /// <summary>
        /// Edit/Change button
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>


private void chgButton_Click(object sender, EventArgs e)
        {
            Assignment_6_attempt_1.ContactFiles.ContactManager mngr = new Assignment_6_attempt_1.ContactFiles.ContactManager();


            string currContact;
                       
            try
            {
                currContact = listBox.SelectedItem.ToString();


                bool flg = mngr.ChangeContact(currContact);
                if (flg)
                    MessageBox.Show("Successfully Changed");
            }


            catch (Exception){ return; }
            UpdateGUI();


Thank you >.<




Answers (1)