0

所以我编写了一个代码来重新排序列表视图的列(实际上只是 -=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
4

1 回答 1

0

看看这篇文章片段。

// 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();
于 2013-01-20T14:01:18.653 回答