2
如何在wpf -xaml(C#)中編寫代碼以讀取.csv文件中的特定行。 我創建的週期表上的每個按鈕都會進入一個新窗口,在列表視圖中顯示它的具體內容。但那麼我的問題該怎麼做?如何讀取WPF中的.csv文件中的特定行(xaml)
public class Atomic
{
public string Group { get; set; }
public string Period { get; set; }
public string Block { get; set; }
public string Atomicnumber { get; set; }
public string Stateat { get; set; }
public string Electronconfiguration { get; set; }
public string ChemspiderID { get; set; }
public Atomic(string group, string period, string block, string atomicnumber, string stateat, string electronconfiguration, string chemspiderID)
{
Group = group;
Period = period;
Block= block;
Atomicnumber = atomicnumber;
Stateat = stateat;
Electronconfiguration = electronconfiguration;
ChemspiderID = chemspiderID;
}
}
public IEnumerable<Atomic> ReadCSV(string fileName)
{
// We change file extension here to make sure it's a .csv file.
// TODO: Error checking.
string[] lines = File.ReadAllLines(System.IO.Path.ChangeExtension(fileName, ".csv"));
// lines.Select allows me to project each line as a Person.
// This will give me an IEnumerable<Person> back.
return lines.Select(line =>
{
string[] data = line.Split(';');
// We return a person with the data in order.
return new Atomic(data[0], data[1], data[2], data[3], data[4], data[5], data[6]);
});
}
Thnx尋求幫助。我的問題是:當我點擊按鈕btnHydrogen_MouseUp時,它必須讀取.csv文件中的第一行。這也與下一個按鈕btnLithium_MouseUp讀取第二行有關。我必須在每個按鈕事件中放置一個特殊的代碼嗎? – JHINZ