Reference type passing ListView presentation data

Source: Internet
Author: User

Summary of teacher scoring project


Create a SE employee class

1.1//Analyze the project first

* 01. I need to display information about three employees in a ListView control

* Then you can define a 3-length array to host the data you want to display

* 02. Through analysis, we will define such an array

* se[] emps=new se[3];

* 03. Write a method: Assign a value to each item in the array

* 04. Bind the data in the array to the ListView, without traversing to an item in the array,

* form a row in the ListView

Se[] Emps=new se[2];

1.2//write a method to insert data into an SE object array

Public void LoadData ()

{

Emps[0]=new SE ();

Emps[0].id = "001";

Emps[0]. Name = "Bruce Lee";

Emps[0]. age = 15;

EMPS[1] = new SE ();

Emps[1].id = "002";

EMPS[1]. Name = "Cheng Long";

EMPS[1]. age = 15;

}

1.3//write a method that binds the data in the array to the ListView to form a row

Public void Fromarraytolistview ()

{

foreach (SE emp in Emps)

{

Each iteration of an item in the array constitutes a row on the interface

ListViewItem lvitem=new ListViewItem (emp.id);

LVITEM.SUBITEMS.ADD (EMP. Name);

LVITEM.SUBITEMS.ADD (EMP. Age.tostring ());

LVITEM.SUBITEMS.ADD (EMP. Assess);

LVITEM.SUBITEMS.ADD (EMP. Score.tostring ());

LVSHOW.ITEMS.ADD (Lvitem);

}

}

1.4//Double click on the mouse event

private void Lvshow_doubleclick (object sender, EventArgs e)

{

Get the employee selected by the user

Double-click the list interface to bring up the selected employee's information

Frmscore frm=new Frmscore ();

Frm.myitem = Lvshow.selecteditems[0];

frm. Show ();

}

Public ListViewItem myitem;

private void Frmscore_load (object sender, EventArgs e)

{

Txtname.text=myitem. SUBITEMS[1]. Text;

Txtassess.text = myitem. SUBITEMS[3]. Text;

Txtscore.text = myitem. SUBITEMS[4]. Text;

}

1.5//Assign the value in the text box to the MyItem object

private void Btnok_click (object sender, EventArgs e)

{

myitem. SUBITEMS[1]. Text = txtName.Text;

myitem. SUBITEMS[3]. Text = Txtassess.text;

myitem. SUBITEMS[4]. Text = Txtscore.text;

}

Reference type passing ListView presentation data

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.