我将“Procs”类添加为List项:
public static List<Procs> allprocs = new List<Procs>();
因此,当用户填写表单并单击“添加程序”时:
private void btAddProcedure_Click(object sender, EventArgs e)
{
ClaimVars.allprocs.Add(new Procs
{
TreatmentBusinessID = Convert.ToInt32(proLocID.Text),
DiagCodeID = ClaimVars.DiagID,
CPTCodeID = ClaimVars.CPTID,
Charges = Convert.ToDouble(txtCharges.Text),
AmountPaid = Convert.ToDouble(txtPaid.Text),
DateServicedFrom = Convert.ToDateTime(dateTimePicker1.Text),
DateServicedToo = Convert.ToDateTime(dateTimePicker2.Text),
Notes = notesDiagServ.Text
});
// Change the DataSource.
listBox1.DataSource = null;
listBox1.DataSource = ClaimVars.allprocs;
}
}
他们会看到一个新的列表项。
如何显示此类的值而不是添加对象的名称?
添加一个程序后,这就是我的列表框的外观:
Project_LB223.ClaimForms.Procs
Project_LB223.ClaimForms.Procs
Project_LB223.ClaimForms.Procs
Project_LB223.ClaimForms.Procs
这就是我希望它的样子:
1 32 44 33.44 22.17 12/17/09 11:21:52 12/22/09 10:31:64 patient was feeling sick.
2 42 72 12.45 10.67 12/18/09 22:51:22 12/23/09 11:21:25 patient was showing signs of fatigue and shortness of breath.
1 68 57 83.64 55.47 12/19/09 23:25:45 12/24/09 15:38:42 the patient is feeling better.
5 12 22 37.44 23.45 12/22/09 16:81:11 12/25/09 19:35:22 the patient does not have any more symptoms.
答案 0 :(得分:1)
通过调用ToString()
显示您的数据。您可以在类中覆盖此方法以显示您喜欢的数据。
答案 1 :(得分:1)
例如,您可以添加ToString()
方法覆盖,如下所示:
public class Procs
{
public override string ToString()
{
string spaceinbetween = new string(' ', 5);
return TreatmentBusinessID + spaceinbetween + DiagCodeID + spaceinbetween ...
}
}
希望这有帮助。
答案 2 :(得分:1)
您可以使用
实现列布局在这两种情况下,您都需要设置固定宽度的字体,因此使用DataGrid或ListView可能会更好。
答案 3 :(得分:0)
ListBox
无法显示多个列,请改用DataGridView
。