2013-01-20 21 views
0

所以我寫了一個重新排列列表視圖的列表(實際上只是 - = 1和+ = 1是所選列表視圖列的顯示索引,但是當我移動列時,子項仍然存在,它們不會移動。想對應的子項與列移動。如何重新排列listviewitem的子項目?

main.listView1.Columns[listBox1.SelectedIndex].DisplayIndex += 1; 
listBox1.Select(); 
listBox1_SelectedIndexChanged(sender, e); //the code for moving the column to the right 

main.listView1.Columns[listBox1.SelectedIndex].DisplayIndex -= 1; 
listBox1.Select(); 
listBox1_SelectedIndexChanged(sender, e); //the code for moving the column to the left 

回答

0

看一看this文章片段。

// Determine if clicked column is already the column that is being sorted. 
if (e.Column == lvwColumnSorter.SortColumn) 
{ 
    // Reverse the current sort direction for this column. 
    if (lvwColumnSorter.Order == SortOrder.Ascending) 
    { 
     lvwColumnSorter.Order = SortOrder.Descending; 
    } 
    else 
    { 
     lvwColumnSorter.Order = SortOrder.Ascending; 
    } 
} 
else 
{ 
    // Set the column number that is to be sorted; default to ascending. 
    lvwColumnSorter.SortColumn = e.Column; 
    lvwColumnSorter.Order = SortOrder.Ascending; 
} 

// Perform the sort with these new sort options. 
this.listView1.Sort(); 
+0

決不再用頭腦,我只是意識到愚蠢的列表視圖具有拖放列表視圖重新排序功能。抱歉。 –

相關問題