我试图加载ListView中的一个文本文件,但每次我选择一个文件 struct SPatient
{
public string s_sName;
public double s_dSalary;
public SPatient(string sName, double dSalary)
{
s_sName = sName;
s_dSalary = dSalary;
}
public override string ToString()
{
return string.Format("{0}, {1}", s_sName, s_dSalary);
}
}
List<SPatient> m_List = new List<SPatient>();
}
public Form1()
{
InitializeComponent();
}
private void btn_LOAD_Click(object sender, EventArgs e)
{
if (openFileDialog1.ShowDialog() == DialogResult.OK)
{
try
{
FileStream fs = new FileStream(openFileDialog1.FileName, FileMode.Open, FileAccess.Read);
BinaryFormatter bf = new BinaryFormatter();
m_List = (List<SPatient>)bf.Deserialize(fs);
fs.Close();
foreach (SPatient sps in m_List)
{
ListViewItem lvi = new ListViewItem(sps.s_sName);
lvi.SubItems.Add(sps.s_dSalary.ToString());
listView1.Items.Add(lvi);
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
它给我这个消息
"输入流是不是一个有效的二进制格式的开始内容(以字节为单位):4A-44-20-53-69-6C-......"