使用ListView的C#结构 [英] C# structure using listview
本文介绍了使用ListView的C#结构的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
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 -......"
im trying to load a text file in the listview but everytime i choose a file
it give me this message
"The input stream is not a valid binary format. The starting contents (in bytes) are: 4A-44-20-53-69-6C-......"
推荐答案
我很抱歉提出要求,对不起,我不像你那样优秀的程序员...
在这个网站上玩得开心...
i apologize for asking, im sorry im not as good programmer as you...
have fun with this site...
所有对此问题的合理回答将被简化为众所周知的原则垃圾进,垃圾出",请参见http://en.wikipedia.org/wiki/Garbage_in,_garbage_out [
All anyone would reasonable answer to this question will be reduced to a well-known principle "Garbage in, garbage out", see http://en.wikipedia.org/wiki/Garbage_in,_garbage_out[^].
Please read my comment to the question. If this is still not clear, read the article referenced above.
You''re trying to use serialization. Would you expect that a serialization code created based on some concrete object graph will be able to read any garbage?
—SA
这篇关于使用ListView的C#结构的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文