【发布时间】:2016-03-11 10:38:22
【问题描述】:
我在我的班级 Patient 上有一个医疗干预列表,我可以添加该患者所进行的许多医疗干预。 不过,我希望能够搜索患者 ID 并显示患者在控件中进行的所有医疗干预。我一直在尝试 listBox 但它似乎不是正确的选项,而且我不知道如何将列表中的项目添加到控件中。 添加医疗干预时的代码:
foreach (Paciente patient in pacientes)
{
if (patient.id == Convert.ToInt32(txtIDI.Text))
{
patient.intervencoes.Add(txtIntervencaoI.Text);
adicionarI = true;
break;
}
当我搜索 id 并显示所有其他信息时:
bool found = false;
foreach (Paciente patient in pacientes)
{
if (patient.id == Convert.ToInt32(txtIDP.Text))
{
txtNomeP.Text = patient.nome;
txtIdadeP.Text = Convert.ToString(patient.idade);
txtMoradaP.Text = patient.morada;
txtContatoP.Text = patient.contato;
txtEmailP.Text = patient.email;
// This would be where I would place my code displaying the items from the patient.intervencoes list
found = true;
break;
}
我应该使用哪个控件以及如何显示来自 patient.intervencoes(列表)的项目?谢谢!
【问题讨论】:
-
ListBox 似乎很明智;你不能这样做吗:lstbx.Add('intervention')? “intervencoes”是 Paciente 类的 ListBox 成员吗? “pacientes”是 Paciente 类的通用列表吗?
-
Pacientes 是包含干预的类,它是一个 List
。不,我无法执行 listbox.Add 或 listbox.Items.Add(patient.intervencoes) 因为它是 List ,而不是 string。
标签: c# list class controls items