タイトルのように、WPFアプリケーションのリストボックスにCSVの情報を入力しようとしています。理想的には、CSVのすべての行を表示したいが、特定の列、つまりフィットネスデータがある場合は、名字、DOB、性別などが表示されますが、姓と名のみが表示されます。次のように私のコードは次のとおりです。リストからCSVのリストボックスを読み込む<>
public partial class PatientList : Window
{
int x = 0;
public PatientList()
{
InitializeComponent();
HumanResources ListAllPatients = new HumanResources();
List<PatientInformation> AllPatients = ListAllPatients.PopPatientList();
foreach (PatientInformation PatientChoice in AllPatients)
{
lboxPatients.Items.Add(AllPatients[x]);
x += 1;
}
}
人事クラス
public List<PatientInformation> PopPatientList()
{
DataAccess PatientList4Doc = new DataAccess();
List<PatientInformation> DocsPatients = PatientList4Doc.ListofPatients();
return DocsPatients;
}
データアクセスクラス
class DataAccess
{
public List<PatientInformation> ListofPatients()
{
List<PatientInformation> ListofPatients = new List<PatientInformation>();
string[] UserData = File.ReadAllLines("UserList.csv");
foreach (string Person in UserData)
{
string[] PersonInfo = Person.Split(',');
PatientInformation Patient = new PatientInformation()
{
Username = PersonInfo[0].ToUpper(),
LastName = PersonInfo[1],
FirstName = PersonInfo[2],
DOB = Convert.ToDateTime(PersonInfo[3]),
Gender = Convert.ToChar(PersonInfo[4]),
Height = Convert.ToInt16(PersonInfo[5]),
Weight = Convert.ToInt16(PersonInfo[6]),
CaloricIntake = PersonInfo[7],
WaterDrank = PersonInfo[8],
CaloriesBurned = PersonInfo[9],
TimeSlept = PersonInfo[10],
ContextMessage = PersonInfo[11],
Replymessage = PersonInfo[12]
};
ListofPatients.Add(Patient);
}
return ListofPatients;
}
患者情報クラス
public class PatientInformation
{
public string Username { get; set; }
public string LastName { get; set; }
public string FirstName { get; set; }
public DateTime DOB { get; set; }
public char Gender { get; set; }
public int Height { get; set; }
public int Weight { get; set; }
public string CaloricIntake { get; set; }
public string WaterDrank { get; set; }
public string CaloriesBurned { get; set; }
public string TimeSlept { get; set; }
public string ContextMessage { get; set; }
public string Replymessage { get; set; }
}
私がしようとするまで、すべてがアップ正常に動作しますlを入力するistbox。情報を読み込もうとすると、目的の情報の代わりにコードパスが取得されます。私の質問です:CSVからすべての情報を取得したら、それをリストボックスに印刷してPatientInformationのものをどのように表示できますか?任意の助けを事前に感謝
EDIT
@Hypnos:
I tried implementing your example like so: HumanResources ListAllPatients = new HumanResources();
List<PatientInformation> AllPatients = ListAllPatients.PopPatientList();
List<PatientInformation> p = new List<PatientInformation>();
p.Add(new PatientInformation() { Username = Convert.ToString(AllPatients[0]), FirstName = Convert.ToString(AllPatients[2]), LastName = Convert.ToString(AllPatients[1]) });
lboxPatients.ItemsSource = p;
しかし、これは「インデックスのうち、例外で返します。私はそうのようなあなたの提案を実装範囲は負でなく、コレクションのサイズより小さくなければなりません "