The error-prone method of ListView in C #

Source: Internet
Author: User

There is now a ListView (LV1), with 2 columns.

ListViewItem LVI = new ListViewItem ();

Lvi. Text = "Language";

Lvi. SubItems.Add ("99");

Lvi. Items.Add (LVI);

LVI = new ListViewItem ();

Lvi. Text = "Mathematics";

Lvi. SubItems.Add ("100");

Lvi. Items.Add (LVI);

A classmate looks like this: listviewitem[] Lvis = LVI. Items.Find ("math", true);

Or this: listviewitem[] Lvis = LVI. items["mathematics"];

This will not be the result. Because the first parameter in Find is key, which is the name of ListViewItem, because neither of the ListView has the name set, it is not possible to get the desired result. Lvi. items["mathematics");

If you modify the code as follows:

LVI = new ListViewItem ();

Lvi. Text = "Mathematics";

Lvi. Name = "Mathematics";

Lvi. SubItems.Add ("100");

Lvi. Items.Add (LVI);

You can get the results you want.

It is recommended to use the FindItemWithText method if you only want to find the relevant lines based on the text:

ListViewItem Lvitem = This.lv1.FindItemWithText ("Mathematics", true, 0);

The error-prone method of ListView in C #

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.