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);
}
}
{
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 { get; set; }
public string CountryAbbreviation { get; set; }
public string LastModifyTime { get; set; }
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);
}
}
{
public string CountryName { get; set; }
public string CountryAbbreviation { get; set; }
public string LastModifyTime { get; set; }
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 += " ) ";
}
}
}
{
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 += " ) ";
}
}
}

