SE類是定義員工的基本屬性 工號workid 年齡age 姓名nane 評分pmscore 評價 pmpingjia 爲設計對象數組作準備數組
主頁面用listview作爲顯示員工信息的載體 listview在父容器中停靠this
在小三角點擊中添加項 添加五項信息標題spa
public SE[] nameandid = new SE[3];
public FrmShow()
{
InitializeComponent();
}設計
private void FrmShow_Load(object sender, EventArgs e)
{3d
ShuZ();
Show();對象
}blog
//賦初始值
public void ShuZ()
{
SE sums = new SE();
sums.Workid = 111;
sums.Age = 18;
sums.Name = "張三";
sums.Pmpingjia = "未評價";
sums.Pmscore = 0;
nameandid[0] = sums;string
SE sumo = new SE();
sumo.Workid = 112;
sumo.Age = 23;
sumo.Name = "李四";
sumo.Pmpingjia = "未評價";
sumo.Pmscore = 0;
nameandid[1] = sumo;it
SE sumt = new SE();
sumt.Workid = 115;
sumt.Age = 27;
sumt.Name = "王五";
sumt.Pmpingjia = "未評價";
sumt.Pmscore = 0;
nameandid[2] = sumt;
for循環
}
public void Show()
{
lvShow.Items.Clear();
for (int i = 0; i < nameandid.Length; i++)
{
string id = nameandid[i].Workid.ToString();
string age = nameandid[i].Age.ToString();
string score = nameandid[i].Pmscore.ToString();
string name = nameandid[i].Name;
string pingjia = nameandid[i].Pmpingjia;
ListViewItem item = new ListViewItem(id);
// item.SubItems.Add(id);
item.SubItems.Add(name);
item.SubItems.Add(age);
item.SubItems.Add(pingjia);
item.SubItems.Add(score);
lvShow.Items.Add(item);
}
}
private void lvShow_DoubleClick(object sender, EventArgs e)
{
if (this.lvShow.SelectedItems.Count == 0)
{
MessageBox.Show("請選擇正確的信息");
return;
}
else
{
ListViewItem lvitem = lvShow.SelectedItems[0];
FrmPinJia pj = new FrmPinJia();
pj.lvitem = lvitem;
pj.Show();
}
}
顯示頁面的代碼如上 程序運行後爲下圖
實現該效果的主要代碼以下
經過for循環對 對象數組循環遍歷
for (int i = 0; i < nameandid.Length; i++)
{
string id = nameandid[i].Workid.ToString();
string age = nameandid[i].Age.ToString();
string score = nameandid[i].Pmscore.ToString();
string name = nameandid[i].Name;
string pingjia = nameandid[i].Pmpingjia;
ListViewItem item = new ListViewItem(id);
// item.SubItems.Add(id);
item.SubItems.Add(name);
item.SubItems.Add(age);
item.SubItems.Add(pingjia);
item.SubItems.Add(score);
lvShow.Items.Add(item);
}
當雙擊listview項時員工評價將相應
當對員工進行評價後點擊評分後 主頁面的顯示將做出相應的變化
實現該效果主要運用了窗體傳值