简体   繁体   中英

how can i find a list item with a list item's given parameter?

how can i find a list item with a list item's given parameter?

my list is defined as;

public List<Column0A> list0A = new List<Column0A>();

and has items as;

list0A.Add(new Column0A(header.type, message.receieveTime, message.importance, message.data));

i have listed all the message.receiveTime's on my GUI depending on my list. what i really want is; when a user click on receiveTime label, i want to show a tooltip which shows the list item's (same receive time) all data like this:

Header: header.type

Receive Time: receiveTime

Importance: message.Importance

Data: message.data

how can i find the same receieveTime list instance? should i use LINQ? could you give me a code sample?

thanks.

I'd recommend that you use an ID as the lookup instead of the time stamp. If this info comes from a database, this would probably be the primary key field. It makes your intent clearer, and allows you to select the right info if two happen to have the same time. Then to select your item:

int theIdImLookingFor = //the one they just clicked on
Column0A myItem = list0A.Single(x => x.ID == theIdImLookingFor);
//display myItem's info in a tooltip

( Single is a LINQ extension) If you're not already clear on it, you should study the difference between Single , First , SingleOrDefault , and FirstOrDefault , and choose the one appropriate for you situation.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM