<p style=" <span>Write a Windows Application that maintains an address book. This address book should hold up to 20 entries. You must store your data with arrays. Each address entry will have the following:
<p style=" <span style=" â <span style="font:7pt "Times New Roman"
<span>Last Name, First Name
<p style=" <span style=" â <span style="font:7pt "Times New Roman"
<span>Street Address
<p style=" <span style=" â <span style="font:7pt "Times New Roman"
<span>City
<p style=" <span style=" â <span style="font:7pt "Times New Roman"
<span>State
<p style=" <span style=" â <span style="font:7pt "Times New Roman"
<span>Zip Code
I am trying to create a program that will hold 20 entries in a list box. It has to contain 5 text boxes. In the listbox only the first and last name of the entry is to be displayed and once you click on the name the info is supposed to show back in the text
boxes. Here is my code and a screen shot of my program and a screen show of how it should come out. Any help is appreciated.
using System;<br/>
using System.Collections.Generic;<br/>
using System.ComponentModel;<br/>
using System.Data;<br/>
using System.Drawing;<br/>
using System.Linq;<br/>
using System.Text;<br/>
using System.Windows.Forms;<br/>
namespace AddressBook<br/>
{<br/>
<br/>
public partial class Form1 : Form<br/>
{<br/>
<br/>
string[] AddressData = new string[10];<br/>
<br/>
int i = 0;<br/>
<br/>
public Form1()<br/>
{<br/>
<br/>
InitializeComponent();<br/>
<br/>
}<br/>
<br/>
<br/>
<br/>
private void btnAdd_Click(object sender, EventArgs e)<br/>
{<br/>
<br/>
string FirstName = fNametextBox.Text;<br/>
<br/>
string LastName = lNametextBox.Text;<br/>
<br/>
string Address = AddresstextBox.Text;<br/>
<br/>
string City = CitytextBox.Text;<br/>
<br/>
string State = StatetextBox.Text;<br/>
<br/>
string Zip = ZiptextBox.Text;<br/>
<br/>
<br/>
<br/>
string Element = String.Format("{0},{1},{2},{3},{4},{5}", FirstName, LastName, Address, City, State, Zip);<br/>
<br/>
<br/>
<br/>
<br/>
<br/>
if (i < 10)<br/>
{<br/>
<br/>
AddressData = Element;<br/>
<br/>
i++;<br/>
<br/>
}<br/>
<br/>
else<br/>
{<br/>
<br/>
MessageBox.Show("Addressbook Full!!");<br/>
<br/>
}<br/>
<br/>
<br/>
<br/>
//Clear TextBoxes<br/>
<br/>
fNametextBox.Text = "";<br/>
<br/>
lNametextBox.Text = "";<br/>
<br/>
AddresstextBox.Text = "";<br/>
<br/>
CitytextBox.Text = "";<br/>
<br/>
StatetextBox.Text = "";<br/>
<br/>
ZiptextBox.Text = "";<br/>
<br/>
<br/>
<br/>
<br/>
<br/>
//Diplay Records in ListBox<br/>
<br/>
listBox1.Items.Clear();<br/>
<br/>
for (int j = 0; j < 10; j++)<br/>
{<br/>
<br/>
if (AddressData[j] != null)<br/>
{<br/>
<br/>
listBox1.Items.Add(AddressData[j].ToString().Trim());<br/>
<br/>
}<br/>
<br/>
}<br/>
<br/>
<br/>
<br/>
<br/>
<br/>
}<br/>
<br/>
<br/>
<br/>
<br/>
<br/>
<br/>
private void btnClearSearch_Click(object sender, EventArgs e)<br/>
{<br/>
<br/>
listBox1.Items.Clear();<br/>
<br/>
for (int j = 0; j < 10; j++)<br/>
{<br/>
<br/>
if (AddressData[j] != null)<br/>
{<br/>
<br/>
listBox1.Items.Add(AddressData[j].ToString().Trim());<br/>
<br/>
}<br/>
<br/>
}<br/>
<br/>
}<br/>
<br/>
private void btnExit_Click(object sender, EventArgs e)<br/>
{<br/>
this.Close();<br/>
}<br/>
<br/>
private void btnSearch_Click(object sender, EventArgs e)<br/>
{<br/>
<br/>
listBox1.Items.Clear();<br/>
<br/>
<br/>
<br/>
for (int k = 0; k < AddressData.Length; k++)<br/>
{<br/>
<br/>
try<br/>
{<br/>
<br/>
if (AddressData[k].Contains(txtSearch.Text) == true && AddressData[k] != null)<br/>
{<br/>
<br/>
listBox1.Items.Add(AddressData[k].ToString());<br/>
<br/>
<br/>
<br/>
}<br/>
<br/>
}<br/>
<br/>
catch<br/>
{<br/>
<br/>
}<br/>
<br/>
<br/>
<br/>
}<br/>
<br/>
txtSearch.Text = "";<br/>
<br/>
}<br/>
<br/>
<br/>
private void btnDelete_Click(object sender, EventArgs e)<br/>
{<br/>
<br/>
for (int k = 0; k < AddressData.Length; k++)<br/>
{<br/>
<br/>
try<br/>
{<br/>
<br/>
if (AddressData[k].Contains(listBox1.SelectedItem.ToString()))<br/>
{<br/>
<br/>
AddressData[k] = null;<br/>
<br/>
}<br/>
<br/>
}<br/>
<br/>
catch<br/>
{<br/>
<br/>
<br/>
<br/>
}<br/>
<br/>
<br/>
<br/>
}<br/>
<br/>
<br/>
<br/>
//Display Refreshed Records in ListBox<br/>
<br/>
<br/>
<br/>
listBox1.Items.Clear();<br/>
<br/>
for (int j = 0; j < 10; j++)<br/>
{<br/>
<br/>
if (AddressData[j] != null)<br/>
{<br/>
<br/>
listBox1.Items.Add(AddressData[j].ToString().Trim());<br/>
<br/>
}<br/>
<br/>
}<br/>
<br/>
<br/>
<br/>
}<br/>
<br/>
}<br/>
<br/>
<br/>
<br/>
}<br/>
<br/>
<br/>
<br/>
<br/>
<br/>
<div id="x_image3212" style=" <a name="x_image3212anc <img src="http://www.kucourses.com/ec/media/store/mediainfosys/IT254_0903B/IT254_10/images/image_2_3211.jpg" border="0" alt="" width="413" height="324
<a name="x_text3181anc <span>This is how it should look.
<span>My program is showing all the info in the listbox and when you click on the name none of the info is showing back in the text boxes.<br/>
<img src="file:///C:/Users/Josh/AppData/Local/Temp/moz-screenshot-1.png" alt="
View the full article
<p style=" <span style=" â <span style="font:7pt "Times New Roman"
<span>Last Name, First Name
<p style=" <span style=" â <span style="font:7pt "Times New Roman"
<span>Street Address
<p style=" <span style=" â <span style="font:7pt "Times New Roman"
<span>City
<p style=" <span style=" â <span style="font:7pt "Times New Roman"
<span>State
<p style=" <span style=" â <span style="font:7pt "Times New Roman"
<span>Zip Code
I am trying to create a program that will hold 20 entries in a list box. It has to contain 5 text boxes. In the listbox only the first and last name of the entry is to be displayed and once you click on the name the info is supposed to show back in the text
boxes. Here is my code and a screen shot of my program and a screen show of how it should come out. Any help is appreciated.
using System;<br/>
using System.Collections.Generic;<br/>
using System.ComponentModel;<br/>
using System.Data;<br/>
using System.Drawing;<br/>
using System.Linq;<br/>
using System.Text;<br/>
using System.Windows.Forms;<br/>
namespace AddressBook<br/>
{<br/>
<br/>
public partial class Form1 : Form<br/>
{<br/>
<br/>
string[] AddressData = new string[10];<br/>
<br/>
int i = 0;<br/>
<br/>
public Form1()<br/>
{<br/>
<br/>
InitializeComponent();<br/>
<br/>
}<br/>
<br/>
<br/>
<br/>
private void btnAdd_Click(object sender, EventArgs e)<br/>
{<br/>
<br/>
string FirstName = fNametextBox.Text;<br/>
<br/>
string LastName = lNametextBox.Text;<br/>
<br/>
string Address = AddresstextBox.Text;<br/>
<br/>
string City = CitytextBox.Text;<br/>
<br/>
string State = StatetextBox.Text;<br/>
<br/>
string Zip = ZiptextBox.Text;<br/>
<br/>
<br/>
<br/>
string Element = String.Format("{0},{1},{2},{3},{4},{5}", FirstName, LastName, Address, City, State, Zip);<br/>
<br/>
<br/>
<br/>
<br/>
<br/>
if (i < 10)<br/>
{<br/>
<br/>
AddressData = Element;<br/>
<br/>
i++;<br/>
<br/>
}<br/>
<br/>
else<br/>
{<br/>
<br/>
MessageBox.Show("Addressbook Full!!");<br/>
<br/>
}<br/>
<br/>
<br/>
<br/>
//Clear TextBoxes<br/>
<br/>
fNametextBox.Text = "";<br/>
<br/>
lNametextBox.Text = "";<br/>
<br/>
AddresstextBox.Text = "";<br/>
<br/>
CitytextBox.Text = "";<br/>
<br/>
StatetextBox.Text = "";<br/>
<br/>
ZiptextBox.Text = "";<br/>
<br/>
<br/>
<br/>
<br/>
<br/>
//Diplay Records in ListBox<br/>
<br/>
listBox1.Items.Clear();<br/>
<br/>
for (int j = 0; j < 10; j++)<br/>
{<br/>
<br/>
if (AddressData[j] != null)<br/>
{<br/>
<br/>
listBox1.Items.Add(AddressData[j].ToString().Trim());<br/>
<br/>
}<br/>
<br/>
}<br/>
<br/>
<br/>
<br/>
<br/>
<br/>
}<br/>
<br/>
<br/>
<br/>
<br/>
<br/>
<br/>
private void btnClearSearch_Click(object sender, EventArgs e)<br/>
{<br/>
<br/>
listBox1.Items.Clear();<br/>
<br/>
for (int j = 0; j < 10; j++)<br/>
{<br/>
<br/>
if (AddressData[j] != null)<br/>
{<br/>
<br/>
listBox1.Items.Add(AddressData[j].ToString().Trim());<br/>
<br/>
}<br/>
<br/>
}<br/>
<br/>
}<br/>
<br/>
private void btnExit_Click(object sender, EventArgs e)<br/>
{<br/>
this.Close();<br/>
}<br/>
<br/>
private void btnSearch_Click(object sender, EventArgs e)<br/>
{<br/>
<br/>
listBox1.Items.Clear();<br/>
<br/>
<br/>
<br/>
for (int k = 0; k < AddressData.Length; k++)<br/>
{<br/>
<br/>
try<br/>
{<br/>
<br/>
if (AddressData[k].Contains(txtSearch.Text) == true && AddressData[k] != null)<br/>
{<br/>
<br/>
listBox1.Items.Add(AddressData[k].ToString());<br/>
<br/>
<br/>
<br/>
}<br/>
<br/>
}<br/>
<br/>
catch<br/>
{<br/>
<br/>
}<br/>
<br/>
<br/>
<br/>
}<br/>
<br/>
txtSearch.Text = "";<br/>
<br/>
}<br/>
<br/>
<br/>
private void btnDelete_Click(object sender, EventArgs e)<br/>
{<br/>
<br/>
for (int k = 0; k < AddressData.Length; k++)<br/>
{<br/>
<br/>
try<br/>
{<br/>
<br/>
if (AddressData[k].Contains(listBox1.SelectedItem.ToString()))<br/>
{<br/>
<br/>
AddressData[k] = null;<br/>
<br/>
}<br/>
<br/>
}<br/>
<br/>
catch<br/>
{<br/>
<br/>
<br/>
<br/>
}<br/>
<br/>
<br/>
<br/>
}<br/>
<br/>
<br/>
<br/>
//Display Refreshed Records in ListBox<br/>
<br/>
<br/>
<br/>
listBox1.Items.Clear();<br/>
<br/>
for (int j = 0; j < 10; j++)<br/>
{<br/>
<br/>
if (AddressData[j] != null)<br/>
{<br/>
<br/>
listBox1.Items.Add(AddressData[j].ToString().Trim());<br/>
<br/>
}<br/>
<br/>
}<br/>
<br/>
<br/>
<br/>
}<br/>
<br/>
}<br/>
<br/>
<br/>
<br/>
}<br/>
<br/>
<br/>
<br/>
<br/>
<br/>
<div id="x_image3212" style=" <a name="x_image3212anc <img src="http://www.kucourses.com/ec/media/store/mediainfosys/IT254_0903B/IT254_10/images/image_2_3211.jpg" border="0" alt="" width="413" height="324
<a name="x_text3181anc <span>This is how it should look.
<span>My program is showing all the info in the listbox and when you click on the name none of the info is showing back in the text boxes.<br/>
<img src="file:///C:/Users/Josh/AppData/Local/Temp/moz-screenshot-1.png" alt="
View the full article