public partial class AddressBook : Form
    {


        public int Counter = 0;
        //declaring array with 20 elements    
        public string[] arrayString = new string[20];

        public AddressBook()
        {
            InitializeComponent();

            this.contactList.SelectedIndexChanged += new System.EventHandler
                    (this.contactList_SelectedIndexChanged);

        }
        private void frmAddressBook_Load(object sender, EventArgs e)
        {      
                           


        }

        private void btnAdd_Click_1(object sender, EventArgs e)
        {

            //my add button with stored array store up to 20 entries         
            //execute the counter as incrementor  
            Counter++;

            //compare the counter less than 20 
            if (Counter <= 20)
            {

                //initializing and store array to display to textbox   
                arrayString[0] = lastNameText.Text;
                arrayString[1] = firstNameText.Text;
                arrayString[2] = streetAddressText.Text;
                arrayString[3] = cityText.Text;
                arrayString[4] = stateText.Text;
                arrayString[5] = zipCodeText.Text;

                //add a list of names by lastname with separator as format 
                contactList.Items.Add(arrayString[0] + ", " + arrayString[1]);

                //alphabetical order           
                contactList.Sorted = true;

                //string empty and brings back the focus to lastname textbox   
                //making room for more information      
                firstNameText.Text = String.Empty;
                lastNameText.Text = String.Empty;
                streetAddressText.Text = String.Empty;
                cityText.Text = String.Empty;
                stateText.Text = String.Empty;
                zipCodeText.Text = String.Empty;
                firstNameText.Focus();
            }
            else
            {
                //otherwise an error messagebox will appear  
                //alerting the user that only 20 entries are permitted    
                MessageBox.Show("You've reached 20 Addresses...permitted", "Error");

            }
        }


        private void btnDelete_Click(object sender, EventArgs e)
        {
            //decision to delete a record from listbox 
            if (contactList.SelectedIndex > -1)
            {
                contactList.Items.RemoveAt(contactList.SelectedIndex);
                firstNameText.Clear();
                lastNameText.Clear();
                streetAddressText.Clear();
                cityText.Clear();
                stateText.Clear();
                zipCodeText.Clear();
            }
        }

        private void exitButton_Click(object sender, EventArgs e)
        {
            //Exits the program
            this.Close();
        }
        private void firstNameText_TextChanged(object sender, EventArgs e)
        {
            //Make this the insertion point
            firstNameText.Focus();
        }
        private void contactList_SelectedIndexChanged(object sender, EventArgs e)
        {
        
        }
        private void btnDisplay_Click(object sender, EventArgs e)
        {



            } 

       
            
        

        private void AddressBook_Load(object sender, EventArgs e)
        {

            

            }

        private void exitButton_Click_1(object sender, EventArgs e)
        {
            //Exits the program
            this.Close();
        }
        }
    }

Edited 6 Years Ago by __avd: Added [code] tags. For easy readability, always wrap programming code within posts in [code] (code blocks).

Could u rephrase,do u want to display the information back to the text boxes,coz ur question is not realy clear.

start quote:

public partial class AddressBook : Form
    {


        public int Counter = 0;
        //declaring array with 20 elements    
        public string[] arrayString = new string[20];

        public AddressBook()
        {
            InitializeComponent();

            this.contactList.SelectedIndexChanged += new System.EventHandler
                    (this.contactList_SelectedIndexChanged);

        }
        private void frmAddressBook_Load(object sender, EventArgs e)
        {      



        }

        private void btnAdd_Click_1(object sender, EventArgs e)
        {

            //my add button with stored array store up to 20 entries         
            //execute the counter as incrementor  
            Counter++;

            //compare the counter less than 20 
            if (Counter <= 20)
            {

                //initializing and store array to display to textbox   
                arrayString[0] = lastNameText.Text;
                arrayString[1] = firstNameText.Text;
                arrayString[2] = streetAddressText.Text;
                arrayString[3] = cityText.Text;
                arrayString[4] = stateText.Text;
                arrayString[5] = zipCodeText.Text;

                //add a list of names by lastname with separator as format 
                contactList.Items.Add(arrayString[0] + ", " + arrayString[1]);

                //alphabetical order           
                contactList.Sorted = true;

                //string empty and brings back the focus to lastname textbox   
                //making room for more information      
                firstNameText.Text = String.Empty;
                lastNameText.Text = String.Empty;
                streetAddressText.Text = String.Empty;
                cityText.Text = String.Empty;
                stateText.Text = String.Empty;
                zipCodeText.Text = String.Empty;
                firstNameText.Focus();
            }
            else
            {
                //otherwise an error messagebox will appear  
                //alerting the user that only 20 entries are permitted    
                MessageBox.Show("You've reached 20 Addresses...permitted", "Error");

            }
        }


        private void btnDelete_Click(object sender, EventArgs e)
        {
            //decision to delete a record from listbox 
            if (contactList.SelectedIndex > -1)
            {
                contactList.Items.RemoveAt(contactList.SelectedIndex);
                firstNameText.Clear();
                lastNameText.Clear();
                streetAddressText.Clear();
                cityText.Clear();
                stateText.Clear();
                zipCodeText.Clear();
            }
        }

        private void exitButton_Click(object sender, EventArgs e)
        {
            //Exits the program
            this.Close();
        }
        private void firstNameText_TextChanged(object sender, EventArgs e)
        {
            //Make this the insertion point
            firstNameText.Focus();
        }
        private void contactList_SelectedIndexChanged(object sender, EventArgs e)
        {

        }
        private void btnDisplay_Click(object sender, EventArgs e)
        {



            } 





        private void AddressBook_Load(object sender, EventArgs e)
        {



            }

        private void exitButton_Click_1(object sender, EventArgs e)
        {
            //Exits the program
            this.Close();
        }
        }
    }

Edited 3 Years Ago by mike_2000_17: Fixed formatting

Could u rephrase,do u want to display the information back to the text boxes,coz ur question is not realy clear.

I would like to have the user click display button when a contact name is selected in the listbox, and display all information for that contact in textboxes for first name, last name, street address, city, state, zip code.

I would like to have the user click display button when a contact name is selected in the listbox, and display all information for that contact in textboxes for first name, last name, street address, city, state, zip code.

Yes, I want the information to display back to the textboxes.

I think you need a slight redesign. Perhaps I'm misunderstanding your intentions but you are making an array of 20 strings but each entry will take up 6 of those strings. You'll only have 3 records. I would make a list of string arrays that are each 6 elements long. Then it's just a matter of matching up the index in the list box with the index of the list and assigning the elements to the appropriate TextBox.Text. So figure out how you'd like to store your information (there are other options beyond the one I suggested of course) and post back with your code.

******************************************************

Hi BarbJones7,
Actually you have to make several changes in your code.
for starters:

public string[,] addressString = new String[20, 7];

this will give the user to enter data in a two dimensional array and will only accept no more than 20 addresses. The 7 is simply the amount of textboxes where the data will go to when selected from the listbox.

You will alsso need to loop around the addressArray

for (int index = 0; index < 20; index++)

Try this on your addButton:

int addressCounter;
            
            //  Check to see if the address book is full with 20 addresses.

            if (btnClickCounter <= 20)
                                    
            {
                
                //  Sets the array index. 
                                
                addressCounter = btnClickCounter - 1;
                        
                //  Fills in the array with the data entered by the user. 
    
                addressString[addressCounter, 0] = txtFirst.Text;
                addressString[addressCounter, 1] = txtLast.Text;
                addressString[addressCounter, 2] = txtAdd1.Text;
                addressString[addressCounter, 3] = txtAdd2.Text;
                addressString[addressCounter, 4] = txtCity.Text;
                addressString[addressCounter, 5] = txtState.Text;
                addressString[addressCounter, 6] = txtZip.Text;
                
                //  Places the Last Name, First Name into the list box.
                              
                lstBxNames.Items.Add(addressString[addressCounter, 1] + ", " + addressString[addressCounter, 0]);
                        
                //  Sorts the list box by Last Name, First Name.
                
                lstBxNames.Sorted = true;
        
                //  Clears the input fields for a new address input.
                    
                txtFirst.Text = "";
                txtLast.Text = "";
                txtAdd1.Text = "";
                txtAdd2.Text = "";
                txtCity.Text = "";
                txtState.Text = "";
                txtZip.Text = "";
                
                //  Sets the focus back to First Name Text Box. 
                
                txtFirst.Focus();

                //  Add a button click to count how many addresses.

                btnClickCounter++;
                
            }

            else
            
            {
                //  If over 20 addresses.     
                    
                MessageBox.Show("Only 20 Addresses permitted", "Error");

                txtFirst.Text = "";
                txtLast.Text = "";
                txtAdd1.Text = "";
                txtAdd2.Text = "";
                txtCity.Text = "";
                txtState.Text = "";
                txtZip.Text = "";

                //  Sets the focus back to First Name Text Box. 

                txtFirst.Focus();
            }
        
        }


        private void btnExit_Click(object sender, EventArgs e)
        {

            //  This button will exit the program.

            this.Close();

        }
This article has been dead for over six months. Start a new discussion instead.