四期三期内必出:

- “ϵԒ - - У· - VӅ^ɽ·A@^3307(AT)
Fڵλã ӋCӖ >> Ӗ̳ >> C# >> 
C#мӏListViewؼĹ ߣӋC࡭    ̳́ԴVӋCӖ    c    •rg2010-11-30

ϴȫ www.wzfng.com njFListViewؼԶx,ӆListViewؼColumnClick¼
 PRivate void listView1_ColumnClick(object sender, ColumnClickEventArgs e)
  {
  if (this.listView1.Columns[e.Column].Tag == null)
  this.listView1.Columns[e.Column].Tag = true;
  bool tabK = (bool)this.listView1.Columns[e.Column].Tag;
  if (tabK)
  this.listView1.Columns[e.Column].Tag = false;
  else
  this.listView1.Columns[e.Column].Tag = true;
  this.listView1.ListViewItemSorter = new ListViewSort(e.Column, this.listView1.Columns[e.Column].Tag);
  //ָcPI
  this.listView1.Sort();//бMԶx
  }
 

  Ķx:

  ///
  ///ԶxListViewؼ򺯔
  ///

  class ListViewSort : IComparer
  {
  private int col;
  private bool descK;

  public ListViewSort()
  {
  col = 0;
  }
  public ListViewSort(int column, object Desc)
  {
  descK = (bool)Desc;
  col = column; //ǰ,0,1,2...,ListViewؼColumnClick¼f
  }
  public int Compare(object x, object y)
  {
  int tempInt = String.Compare(((ListViewItem)x).SubItems[col].Text, ((ListViewItem)y).SubItems[col].Text);
  if (descK) return -tempInt;
  else return tempInt;
  }
  }
ListViewؼԶxΓListViewؼĘ}rM

  挢FListViewؼһеȥ,Ԅ{mĴС

  Ȍһ{ListViewؼЌĺ

  ///
  ///Ԅ{listViewؼһеЌ
  ///
  ///
  ///

  private void {LVЌ()
  {
  listView1.ColumnWidthChanged -= new ColumnWidthChangedEventHandler(listView1_ColumnWidthChanged);
  ע.AutoResize(ColumnHeaderAutoResizeStyle.HeaderSize);
  listView1.ColumnWidthChanged += new ColumnWidthChangedEventHandler(listView1_ColumnWidthChanged);
  }

  ĂעlistviewؼһеQlistviewؼČlistView1

  ȻӆListViewؼColumnWidthChanged¼Ќ׃rԄ{Ќ

  ///
  /// listviewЌ׃¼
  ///
  ///
  ///

  void listView1_ColumnWidthChanged(object sender, ColumnWidthChangedEventArgs e)
  {
  {LVЌ();
  }

 

  ӆListViewؼSize_Change¼ڴС׃r{Ќ

  void listView1_SizeChanged(object sender, EventArgs e)
  {
  {LVЌ();
  }

  ڴwShown¼{ListViewؼЌһ@ʾĕrR{Ќ

  private void Ʒ_Shown(object sender, EventArgs e)
  {
  {LVЌ();
  }

 

 

WУ· |Wվ؈D| ϴȫ Copyright 2006-2016 All Rights Reserved VϢԃ޹˾ 䰸/SC̖ICP11070650̖-9 B̩˱BϢg޹˾VӋCWУӖW ٷWַϴȫ www.wzfng.com ˾ַVӅ^ɽ·AWƼ@A@^3307AT