public FrmShow()
{
InitializeComponent();
this.Init();//初始化员工信息
this.UpdateView();//将员工信息绑定到listView1上
}
//准备一个容器,可以容纳3个员工对象
SE[] engineers = new SE[3];
/// <summary>
/// 初始化员工信息
/// </summary>
public void Init()
{
SE a = new SE();
a.Id = 111;
a.Name = "王小毛";
a.Age = 26;
a.Ping = "未评价";
a.Fen = "0";
engineers[0] = a;
SE b = new SE();
b.Id = 112;
b.Name = "周新雨";
b.Age = 22;
b.Ping = "未评价";
b.Fen = "0";
engineers[1] = b;
SE c= new SE();
c.Id = 112;
c.Name = "张烨";
c.Age = 30;
c.Ping = "未评价";
c.Fen = "0";
engineers[2] = c;
}
/// <summary>
/// 将员工信息绑定到listView1上
/// </summary>
public void UpdateView()
{
listView1.Items.Clear();
for (int i = 0; i < engineers.Length; i++)
{
//一个item就是一个员工对象
ListViewItem item = new ListViewItem(engineers[i].Id.ToString());
item.SubItems.Add(engineers[i].Name.ToString());
item.SubItems.Add(engineers[i].Age.ToString());
item.SubItems.Add(engineers[i].Ping.ToString());
item.SubItems.Add(engineers[i].Fen.ToString());
this.listView1.Items.Add(item);
}
}
private void listView1_DoubleClick(object sender, EventArgs e)
{
ListViewItem selectItem = listView1.SelectedItems[0];
FrmJudge frm = new FrmJudge();
frm.selectItem = selectItem;
frm.ShowDialog();
}
public ListViewItem selectItem = null;
private void FrmJudge_Load(object sender, EventArgs e)
{
txtName.Text = selectItem.SubItems[1].Text;
txtName.ReadOnly = true;
}
private void btnPing_Click(object sender, EventArgs e)
{
selectItem.SubItems[3].Text = rtxtPing.Text;
selectItem.SubItems[4].Text = txtNian.Text;
this.Close();
}