如何重新排序listviewitem的子项?

时间:2013-01-20 13:56:46

标签: c# listview subitem

所以我编写了一个重新排序列表视图列的代码(实际上只是 - = 1和+ = 1是所选列表视图列的显示索引。但是当我移动列时子项保持不变。它们不会移动。我希望相应的子项随列移动。

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

1 个答案:

答案 0 :(得分: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();