C# 如何重新排列listviewitem的子项?
因此,我编写了一段代码,对listview的列进行重新排序(实际上-=1和+=1是所选listview列的显示索引。但是,当我移动列时,子项保持不变。它们不会移动。我希望相应的子项随列一起移动C# 如何重新排列listviewitem的子项?,c#,listview,subitem,C#,Listview,Subitem,因此,我编写了一段代码,对listview的列进行重新排序(实际上-=1和+=1是所选listview列的显示索引。但是,当我移动列时,子项保持不变。它们不会移动。我希望相应的子项随列一起移动 main.listView1.Columns[listBox1.SelectedIndex].DisplayIndex += 1; listBox1.Select(); listBox1_SelectedIndexChanged(sender, e); //the code for moving the
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
看一看文章片段
// 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();
没关系,我只是意识到愚蠢的listview有一个拖放listview重新排序功能。对不起。