ListView의 column을 클릭했을 때 리스트를 정렬하는 예제입니다.
http://whiteat.com/zbxe/33283 예제를 이용하겠습니다.
전체 소스
        
  
주요 소스
             Boolean m_ColumnclickASC = true;
        private void lvwColor_ColumnClick(object sender, ColumnClickEventArgs e)
        {
            if (m_ColumnclickASC == true)
                ((ListView)sender).ListViewItemSorter = new ListViewItemSortASC(e.Column);
            else
                ((ListView)sender).ListViewItemSorter = new ListViewItemSortDESC(e.Column);
m_ColumnclickASC = !m_ColumnclickASC;
}
        class ListViewItemSort : IComparer
        {
            private int col;
            public ListViewItemSort()
            {
                col = 0;
            }
            public ListViewItemSort(int column)
            {
                col = column;
            }
            public int Compare(object x, object y)
            {
                return String.Compare(((ListViewItem)x).SubItems[col].Text, ((ListViewItem)y).SubItems[col].Text);
            }
        }
        class ListViewItemSortASC : IComparer
        {
            private int col;
            public ListViewItemSortASC()
            {
                col = 0;
            }
            public ListViewItemSortASC(int column)
            {
                col = column;
            }
            public int Compare(object x, object y)
            {
                try
                {
                    if (Convert.ToInt32(((ListViewItem)x).SubItems[col].Text) > Convert.ToInt32(((ListViewItem)y).SubItems[col].Text))
                        return 1;
                    else
                        return -1;
                }
                catch (Exception)
                {
                    if (1 != String.Compare(((ListViewItem)x).SubItems[col].Text, ((ListViewItem)y).SubItems[col].Text) )
                        return -1;
                    else
                        return 1;
                }
            }
        }
        class ListViewItemSortDESC : IComparer
        {
            private int col;
            public ListViewItemSortDESC()
            {
                col = 0;
            }
            public ListViewItemSortDESC(int column)
            {
                col = column;
            }
            public int Compare(object x, object y)
            {
                try
                {
                    if (Convert.ToInt32(((ListViewItem)x).SubItems[col].Text) < Convert.ToInt32(((ListViewItem)y).SubItems[col].Text))
                        return 1;
                    else
                        return -1;
                }
                catch (Exception)
                {
                    if (String.Compare(((ListViewItem)x).SubItems[col].Text, ((ListViewItem)y).SubItems[col].Text) == 1)
                        return -1;
                    else
                        return 1;
                }
            }
        }
- [2018/02/26] List 에서 고유값 얻기 ()
- [2015/05/22] C#, 아두이노 간의 WIFI 통신으로 LCD 제어 (4642)
- [2015/03/13] 항상 마지막에 추가한 TEXT 보이게 ()
- [2014/01/17] ComboBox Text 편집 안되게 (15454)
- [2014/01/08] if 문에서 여러개 비교할때 (26025) *3
- [2013/12/30] C++, C# 간단한 기능 비교 (13749)
- [2013/12/18] 3자리마다 ,(콤마) 찍기 (원화, 달러 표시) (15891)
- [2013/09/29] 설치된 IE 버전 얻기 (13305)
- [2013/08/29] byte array to Hexa String (13378)
- [2013/06/25] string array to string (스트링 문자열 합치기) (24575)

 
	
		 


 
    
 
    
 
     
 GroupBox 테투리 색상 변경하기/안보이게 하기
									GroupBox 테투리 색상 변경하기/안보이게 하기
									
 1
1