C# ObjectListView列重新排序
我有一个C# ObjectListView列重新排序,c#,objectlistview,C#,Objectlistview,我有一个dataTreeListView,其中添加了一些列标题,如下所示: oCol2.IsVisible = false; dataTreeListView.AllColumns.AddRange(new OLVColumn[] { oCol1, oCol2, oCol3, oCol4, oCol5}); dataTreeListView.KeyAspectName = id; dataTreeListView.ParentKeyAspectName = ParentId; dataTree
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个属性(包括Id
和ParentId
)
我试图实现的是,在组合框的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
我现在得到的是视图(类型1)工作正常,但是在切换到视图类型2之后,可扩展列仍然位于oCol1而不是oCol2。似乎我无法切换主列
有什么帮助吗?如果您只想更改顺序,请更改每列的DisplayIndex
属性
如果要隐藏/显示列(以及对列重新排序),请更改AllColumns
的内容,然后调用RebuildColumns()
。看
如果要在各种列布局之间切换,可以使用SaveState()
和RestoreState()
请参见type2视图首先定义oCol2,然后定义oCol1(可扩展)。根据你的问题,这看起来像是一个预期的输出。除非我遗漏了什么。嗨,他们好,我试过做类似的事情。dataTreeListView.AllColumns.Clear();oCol2.IsVisible=true;dataTreeListView.AllColumns.AddRange(新的OLVColumn[]{oCol2,oCol1,oCol3,oCol4,oCol5,});结果还是一样,oCol1在第一篇专栏文章中说:嗨,语法学家,我用了另一种方法来处理我的数据显示,谢谢!