ObjectListView列重新排序

时间:2014-01-29 08:41:49

标签: c# objectlistview

我有一个dataTreeListView已经添加了一些列标题,如下所示:

oCol2.IsVisible = false;
dataTreeListView.AllColumns.AddRange(new OLVColumn[] { oCol1, oCol2, oCol3, oCol4, oCol5});

dataTreeListView.KeyAspectName = id;
dataTreeListView.ParentKeyAspectName = ParentId;
dataTreeListView.DataSource = list;
dataTreeListView.RootKeyValue = 0;

列表本身有7个属性(包括IdParentId)。

我想要实现的是,在selectedIndex更改组合框后,列标题将改变位置。

From View (type1) (oCol2.IsVisible = false):
oCol1 (expandable) | oCol2 (hidden) | oCol3 |   oCol4 | oCol5

To View (type2) (oCol2.IsVisible = true):
oCol2 | oCol1 (expandable) | oCol3 | oCol4 | oCol5

我现在得到的是view(type1)正常工作,但在切换到view type2后,可扩展列仍然是oCol1而不是oCol2。我似乎无法switch主要列。

对此有何帮助?

1 个答案:

答案 0 :(得分:1)

如果您只想更改排序,请更改每列的DisplayIndex属性。

如果要隐藏/显示列(以及重新排序列),请更改AllColumns的内容,然后调用RebuildColumns()。见this FAQ

如果您想在各种列布局之间切换,可以使用SaveState()RestoreState()查看this recipe