-
?学生信息显示》的C#程序设计
资源介绍
C#学生信息显示
namespace xuexi6._
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
public student[] sts = new student[10];
private void initializestudent()
{
student st0 = new student();
st0.Name = "赵阳";
st0.Sex = "男";
st0.Jiguan = "嘉兴";
st0.Banji = "计算机一班";
sts[0] = st0;
student st1 = new student();
st1.Name = "蒋林杰";
st1.Sex = "男";
st1.Jiguan = "宁波";
st1.Banji = "计算机一班";
sts[1] = st1;
student st2 = new student();
st2.Name = "邱明峰";
st2.Sex = "男";
st2.Jiguan = "杭州";
st2.Banji = "计算机一班";
sts[2] = st2;
student st3 = new student();
st3.Name = "陆玲燕";
st3.Sex = "女";
st3.Jiguan = "丽水";
st3.Banji = "计算机一班";
sts[3] = st3;
student st4 = new student();
st4.Name = "邵德华";
st4.Sex = "男";
st4.Jiguan = "台州";
st4.Banji = "计算机二班";
sts[4] = st4;
student st5 = new student();
st5.Name = "吴旦";
st5.Sex = "女";
st5.Jiguan = "温州";
st5.Banji = "计算机二班";
sts[5] = st5;
student st6 = new student();
st6.Name = "朱凤";
st6.Sex = "女";
st6.Jiguan = "绍兴";
st6.Banji = "计算机三班";
sts[6] = st6;
student st7 = new student();
st7.Name = "邱小峰";
st7.Sex = "男";
st7.Jiguan = "湖州";
st7.Banji = "计算机三班";
sts[7] = st7;
student st8 = new student();
st8.Name = "沈汉卿";
st8.Sex = "男";
st8.Jiguan = "衡州";
st8.Banji = "计算机三班";
sts[8] = st8;
student st9 = new student();
st9.Name = "王佳俊";
st9.Sex = "男";
st9.Jiguan = "义乌";
st9.Banji = "计算机三班";
sts[9] = st9;
}
private void initializetvstudent()
{
TreeNode firsttn = new TreeNode("学生信息");
TreeNode secondtn1 = new TreeNode(sts[0].Banji);
secondtn1.Nodes.Add(sts[0].Name);
secondtn1.Nodes.Add(sts[1].Name);
secondtn1.Nodes.Add(sts[2].Name);
secondtn1.Nodes.Add(sts[3].Name);
TreeNode secondtn2 = new TreeNode(sts[4].Banji);
secondtn2.Nodes.Add(sts[4].Name);
secondtn2.Nodes.Add(sts[5].Name);
TreeNode secondtn3 = new TreeNode(sts[6].Banji);
secondtn3.Nodes.Add(sts[6].Name);
secondtn3.Nodes.Add(sts[7].Name);
secondtn3.Nodes.Add(sts[8].Name);
secondtn3.Nodes.Add(sts[9].Name);
firsttn.Nodes.AddRange(new TreeNode[] { secondtn1, secondtn2, secondtn3 });
tvstudent.Nodes.Add(firsttn);
}
private void initializelvstudent()
{
ColumnHeader column1 = new ColumnHeader();
column1.Text = "姓名";
lvstudent.Columns.Add(column1);
ColumnHeader column2 = new ColumnHeader();
column2.Text = "性别";
lvstudent.Columns.Add(column2);
ColumnHeader column3 = new ColumnHeader();
column3.Text = "籍贯";
lvstudent.Columns.Add(column3);
ColumnHeader column4 = new ColumnHeader();
column4.Text = "班级";
lvstudent.Columns.Add(column4);
for (int i = 0; i < sts.Length; i++)
{
ListViewItem lvi = new ListViewItem();
lvi.Text = sts[i].Name;
lvi.SubItems.Add(sts[i].Sex);
lvi.SubItems.Add(sts[i].Jiguan);
lvi.SubItems.Add(sts[i].Banji);
lvstudent.Items.Add(lvi);
}
}
private void tvstudentadd(int i)
{
ListViewItem lvi = new ListViewItem();
lvi.Text = sts[i].Name;
lvi.SubItems.Add(sts[i].Sex);
lvi.SubItems.Add(sts[i].Jiguan);
lvi.SubItems.Add(sts[i].Banji);
lvi.ImageIndex = i;
lvstudent.Items.Add(lvi);
}
private void Form1_Load(object sender, EventArgs e)
{
initializestudent();
initializetvstudent();
initializelvstudent();
}
private void tvstudent_AfterSelect(object sender, TreeViewEventArgs e)
{
lvstudent.Items.Clear();
if (e.Node.Text == "学生信息")
{
for (int i = 0; i < sts.Length; i++)
{
tvstudentadd(i);
}
}
else if (e.Node.Text == "计算机一班")
{
for (int i = 0; i < sts.Length; i++)
{
if (sts[i].Banji == e.Node.Text)
{
tvstudentadd(i);
}
}
}
else if (e.Node.Text == "计算机二班")
{
for (int i = 0; i < sts.Length; i++)
{
if (sts[i].Banji == e.Node.Text)
{
tvstudentadd(i);
}
}
}
else if (e.Node.Text == "计算机三班")
{
for (int i = 0; i < sts.Length; i++)
{
if (sts[i].Banji == e.Node.Text)
{
tvstudentadd(i);
}
}
}
else
{
for (int i = 0; i < sts.Length; i++)
{
if (sts[i].Name == e.Node.Text)
{
tvstudentadd(i);
}
}
}
}
public class student
{
private string name;
private string sex;
private string jiguan;
private string banji;
public string Name
{
get
{
return name;
}
set
{
name = value;
}
}
public string Sex
{
get
{
return sex;
}
set
{
sex = value;
}
}
public string Jiguan
{
get
{
return jiguan;
}
set
{
jiguan = value;
}
}
public string Banji
{
get
{
return banji;
}
set
{
banji = value;
}
}
}
private void lvstudent_ItemActivate(object sender, EventArgs e)
{
MessageBox.Show("您选择的是:" + lvstudent.SelectedItems[0].Text);
}
private void btnlargeicon_Click(object sender, EventArgs e)
{
lvstudent.View = View.LargeIcon;
}
private void btnsmallicon_Click(object sender, EventArgs e)
{
lvstudent.View = View.SmallIcon;
}
private void btndetail_Click(object sender, EventArgs e)
{
lvstudent.View = View.Details;
}
private void btnlist_Click(object sender, EventArgs e)
{
lvstudent.View = View.List;
}
private void btntitle_Click(object sender, EventArgs e)
{
lvstudent.View = View.Tile;
}
}
}