日期:2009-06-20  浏览次数:20557 次

Displaying ListView items - with class!  by Rob Birdwell
I don't know about you, but I'm very fond of the ListView control - it's a very useful control to have around. Microsoft's .NET Common Language Runtime (CLR) provides much of the functionality you need to display data in a ListView. However, you're still left will some work to do. Loading the ListView and getting the data can be an arduous task. In fact, your code can get pretty messy unless you think things through a bit. In order to display complex class data, you should consider a way to associate your class data with each ListItem in the ListView.

Let's say you have a class as follows:

class Person                                                                               
   {                                                                                       
   public string Name;                                                                     
   public string Rank;                                                                     
   public string SerialNumber;                                                             
                                                                                           
   public Person (string n, string r, string sn)                             &nbs