What I'm trying to do with this is save a list of reference keys for everything that is populating a listbox. There will be an unknown quantity of lines(users/"patients"). After saving the list, I want to be able to use the listbox index to find the corresponding key, and use that to move on to the next part.
public partial class PatientList : Window
{
HumanResources ListAllPatients;
List<PatientInformation> AllPatients;
string[] Usernames;
public PatientList()
{
InitializeComponent();
int i = 0;
string[] Usernames = new string[i];
ListAllPatients = new HumanResources();
AllPatients = ListAllPatients.PopPatientList();
foreach (PatientInformation PatientChoice in AllPatients)
{
Usernames[i] = PatientChoice.Username;
lboxPatients.Items.Add(string.Format("{0} {1}; {2}", PatientChoice.FirstName, PatientChoice.LastName, PatientChoice.Gender));
i += 1;
}
}
Here is the code for the button that moves you on to the next section
public void btnSelectPatient_Click(object sender, RoutedEventArgs e)
{
PatientInfo PatientInfoWindow = new PatientInfo();
PatientInfoWindow.Show();
//i = lboxPatients.SelectedIndex;
//UserFactory.CurrentUser = Usernames2[i];
this.Close();
}
My issue is this: I believe I've initialized a string array to do this, but VS keeps telling me it isn't assigned to, and will always remain null.
My question: How and where do I properly initialize a string array (or something better) in order to accomplish sending the key from PatientList() to btnSelectPatient?