ListView && XmlReader

ListView:

It's a very good control. The book just introduce it samply.

 

代码
   private void BindListView()
        {
            lv.GridLines 
= true;
            lv.LabelEdit 
= true;
            lv.AllowColumnReorder 
= true;
            
//lv.CheckBoxes = true;
            lv.FullRowSelect = true;
            lv.Sorting 
= SortOrder.Ascending;


            lv.Columns.Add(
"ProcessName");
            lv.Columns.Add(
"Id");
            lv.Columns.Add(
"MainWindowTitle");

            ListViewItem lvItem 
= null;
            
foreach (Process process in System.Diagnostics.Process.GetProcesses())
            {
                lvItem 
= new ListViewItem();
                lvItem.Text 
= process.ProcessName;
                lvItem.SubItems.Add(process.Id);
                lvItem.SubItems.Add(process.MainWindowTitle);

                lv.Items.Add(lvItem);
            }
        }

 

 

 

代码
 public class CountryItem : System.Windows.Forms.ListViewItem
    {
        
public string CountryName { getset; }
        
public string CountryAbbreviation { getset; }
        
public string LastModifyTime { getset; }

        
public CountryItem(string countryName, string countryAbbreviation,
            
string currency, string lastModifyTime)
        {
            
this.CountryName = countryName;
            
this.CountryAbbreviation = countryAbbreviation;
            
this.LastModifyTime = lastModifyTime;
            
base.Text = countryName;
            
base.SubItems.Add(currency);
            
base.SubItems.Add(lastModifyTime);
        }
    }

 

 

XmlReader:

代码
 private void TestXml()
        {         
            XmlReader rdr 
= XmlReader.Create("Favorites.xml");
            
while (rdr.Read())
            {
                
if (rdr.NodeType == XmlNodeType.Element)
                {
                    
this.txtMsg.Text += rdr.Name + "\n\t" + " ( ";
                    
for (int i = 0; i < rdr.AttributeCount; i++)
                    {
                        rdr.MoveToAttribute(i);
                        
this.txtMsg.Text += rdr.Name + ":" + rdr.Value + ";";
                    }
                    
this.txtMsg.Text += " ) ";
                }
            }
        }

 

 

 

posted on 2010-07-07 18:36 林骄 阅读(16) 评论(0) 编辑 收藏