Duchesssix
New member
- Joined
- Oct 19, 2014
- Messages
- 1
- Programming Experience
- Beginner
I am using Net 4.5. This is all new to me, especially programming with WPF instead of console apps.
I need to create a data entry form that keeps all user data in an arraylist for easy display and sort. However, I haven't figured out where to declare the generic collection so every time SAVE is pressed thearray is recreated andI never have more than 1 record at a time. If I move array instantiation outside the button click I get out of context errors. Can anyone help me?
I need to create a data entry form that keeps all user data in an arraylist for easy display and sort. However, I haven't figured out where to declare the generic collection so every time SAVE is pressed thearray is recreated andI never have more than 1 record at a time. If I move array instantiation outside the button click I get out of context errors. Can anyone help me?
C#:
namespace Project4
{
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
public class InputRecord
{
public string firstName { get; set; }
public string lastName { get; set; }
public string address { get; set; }
public string city { get; set; }
public string state { get; set; }
public int zip { get; set; }
public string phone { get; set; }
public InputRecord()
{ }
public InputRecord(string firstName, string lastName, string address,
string city, string state, int zip, string phone)
{
this.firstName = firstName;
this.lastName = lastName;
this.address = address;
this.city = city;
this.state = state;
this.zip = zip;
this.phone = phone;
}
}
public MainWindow()
{
InitializeComponent();
}
private void btnSave_Click(object sender, RoutedEventArgs e)
{
ArrayList myList = new ArrayList();
//dataGrid1.ItemsSource = "";
InputRecord myaddressFiles = new InputRecord();
myaddressFiles.firstName = txtFName.Text;
myaddressFiles.lastName = txtLName.Text;
myaddressFiles.address = txtAddress.Text;
myaddressFiles.city = txtCity.Text;
myaddressFiles.state = txtState.Text;
//myaddressFiles.zip = txtZip.Text;
myaddressFiles.phone = txtPhone.Text;
myList.Add(myaddressFiles);
myList.Sort();
dataGrid1.ItemsSource = myList;
clearData();
}
private void btnClear_Click(object sender, RoutedEventArgs e)
{
clearData();
}
private void clearData()
{
txtFName.Text = "";
txtLName.Text = "";
txtAddress.Text = "";
txtCity.Text = "";
txtState.Text = "";
txtZip.Text = "";
txtPhone.Text = "";
txtFName.Focus();
}
}
}