我想要做的是保存列表框的所有填充參考鍵列表。將有未知數量的線路(用戶/「患者」)。保存列表後,我希望能夠使用列表框索引來查找相應的鍵,並使用它來轉到下一部分。正在初始化數據引用的字符串數組
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;
}
}
這裏是你移動到下一個部分的按鈕的代碼
public void btnSelectPatient_Click(object sender, RoutedEventArgs e)
{
PatientInfo PatientInfoWindow = new PatientInfo();
PatientInfoWindow.Show();
//i = lboxPatients.SelectedIndex;
//UserFactory.CurrentUser = Usernames2[i];
this.Close();
}
我的問題是這樣的:我相信我已經初始化字符串數組來做到這一點,但保持VS告訴我它沒有被分配到,並且一直保持爲空。
我的問題:爲了完成從PatientList()向btnSelectPatient發送密鑰,我如何以及在哪裏正確初始化字符串數組(或更好的方法)?
你在哪裏初始化它? –
我相信我已經初始化它在最上面,在List AllPatients –
Erick